Android TextInputLayout将颜色更改为渐变色
有没有办法改变TextInputLayout的任何颜色,使其具有渐变效果。到目前为止,我看到的答案允许通过XML将正常、激活和突出显示的颜色更改为单一颜色。是的,您只需要创建一个XML形状文件,例如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
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>