Android EditText Style.xml更改焦点EditText
下午好Android EditText Style.xml更改焦点EditText,android,focus,styles,android-edittext,Android,Focus,Styles,Android Edittext,下午好 伙计们,我为所有字段创建了一个样式文件style.xml EditText现在当字段获得焦点时,我想更改样式。怎么做?您必须为编辑文本的每个状态定义可绘制内容。在drawables文件夹中创建一个xml文件,该文件定义编辑文本的所有状态drawables。XML文件如下所示: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res
伙计们,我为所有字段创建了一个样式文件style.xml EditText现在当字段获得焦点时,我想更改样式。怎么做?您必须为编辑文本的每个状态定义可绘制内容。在drawables文件夹中创建一个xml文件,该文件定义编辑文本的所有状态drawables。XML文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
您可以为要指定的每个状态设置一个项目。因此,对于以状态为中心的可绘制图形,您只需执行以下操作:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/myFocusedEditText"
android:state_focused="true"/>
<item
android:drawable="@drawable/myEnabledEditText"
android:state_enabled="true"/>
</selector>
将此XML文件命名为custom_edit_text.XML,确保它位于drawables文件夹中。
然后,您所要做的就是在styles.xml中定义
<style name="my_edit_text">
<item name="android:drawable">@drawable/custom_edit_text</item>
</style>
@可绘制/自定义\u编辑\u文本
祝你好运