更改EditText下划线的颜色 [英] Changing the color of EditText's underline
问题描述
我试图借助此线程来更改EditText的下划线颜色
我做了同样的事情-这是EditText
,其中android:background
设置为@drawable/edt_bg_selector
.
I did the same thing - this is the EditText
with the android:background
set as @drawable/edt_bg_selector
.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/editText4"
android:layout_weight="1"
android:elevation="0dp"
android:background="@drawable/edt_bg_selector" />
我的edt_bg_selector
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/edt_bg_selected" />
<item android:state_focused="false" android:drawable="@drawable/edt_bg_normal" />
</selector>
... edt_bg_normal.xml
...
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="1px"
android:color="@color/colorWhite" />
<solid android:color="#00FFFFFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</layer-list>
...和最后一个edt_bg_selected.xml
.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="1px"
android:color="@color/colorWhite" />
<solid android:color="#00FFFFFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</layer-list>
使用此代码,我可以看到下划线的颜色在Android Studio的设计编辑器中已变为白色.但是,当我在android设备上运行此项目时,尚未进行更改.选定的EditText
的下划线是我的primaryColor
,未选定的EditText
是黑色.
With this code I can see the color of underline has changed to white in Design Editor of Android Studio. But when I run this project on android device, the changes haven't been made. Selected EditText
's underline is my primaryColor
and unselected EditText
is black.
Android Studio设计编辑器:
Android studio design editor:
在android设备上运行的项目:
Project run on android device:
这与我的应用程序的选定主题有关系吗?还是我想念什么?
Does this have anything to do with the selected theme of my application? Or what did I miss?
推荐答案
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Something or Other"
android:backgroundTint="@android:color/holo_green_light" />
注意:仅适用于AP lvl 21或更高版本.
Note: only works with AP lvl 21 or higher.
这篇关于更改EditText下划线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!