Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TextInputLayout将颜色更改为渐变色_Android_Xml_Colors_Gradient_Android Textinputlayout - Fatal编程技术网

Android TextInputLayout将颜色更改为渐变色

Android TextInputLayout将颜色更改为渐变色,android,xml,colors,gradient,android-textinputlayout,Android,Xml,Colors,Gradient,Android Textinputlayout,有没有办法改变TextInputLayout的任何颜色,使其具有渐变效果。到目前为止,我看到的答案允许通过XML将正常、激活和突出显示的颜色更改为单一颜色。是的,您只需要创建一个XML形状文件,例如drawable/mygradient.XML: <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shap

有没有办法改变TextInputLayout的任何颜色,使其具有渐变效果。到目前为止,我看到的答案允许通过XML将正常、激活和突出显示的颜色更改为单一颜色。

是的,您只需要创建一个XML形状文件,例如
drawable/mygradient.XML

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

    <gradient
        android:angle="90"
        android:centerColor="#555994"
        android:endColor="#b5b6d2"
        android:startColor="#555994"
        android:type="linear" />

    <corners
        android:radius="0dp"/>

</shape>


并将
TextInputLayout
的背景设置为
android:background=“@drawable/mygradient”
将其添加为background@drawable/gradient:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <!-- create gradient you want to use with the angle you want to use -->
        <shape android:shape="rectangle" >
            <gradient
                android:angle="0"
                android:centerColor="@android:color/holo_blue_bright"
                android:endColor="@android:color/holo_red_light"
                android:startColor="@android:color/holo_green_light" />

        </shape>
    </item>
    <!-- create the stroke for top, left, bottom and right with the dp you want -->
    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp">
        <shape android:shape="rectangle" >
            <!-- fill the inside in the color you want (could also be a gradient again if you want to, just change solid to gradient and enter angle, start, maybe center, and end color) -->
            <solid android:color="#fff" />
        </shape>
    </item>

</layer-list>