根据焦点状态更改EditText的compoundDrawable权限的色调

时间:2016-03-09 18:09:34

标签: android android-drawable android-styles

我一直试图弄清楚如何在一段时间内改变EditText的compoundDrawable的色调而没有成功。我使用EditText作为按钮,并希望像EditText下划线颜色更改drawable右边的颜色。如何向compoundDrawables添加可绘制状态?

点击时,我想像下划线色调一样着色。

这是我的风格。

<style name="EditTextDropdown" parent="@android:style/Widget.EditText">
    <item name="android:clickable">true</item>
    <item name="android:fontFamily">sans-serif</item>
    <item name="android:focusable">false</item>
    <item name="android:focusableInTouchMode">true</item>
    <item name="android:singleLine">true</item>
    <item name="android:cursorVisible">false</item>
    <item name="android:layout_marginLeft">16dp</item>
    <item name="android:layout_marginRight">16dp</item>
    <item name="android:drawableRight">@drawable/ic_drop_down_arrow_24dp</item>
</style>

的EditText

<EditText
    android:id="@+id/phone"
    style="@style/EditTextDropdown"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Add phone" />

这是正常的

Normal

这是按下时的样子

Pressed

1 个答案:

答案 0 :(得分:0)

您可以直接覆盖EditText的外观,方法是在应用中style的{​​{1}}中重新分配该属性。

给定代码会覆盖Theme外观。

EditText

<item name="android:editTextBackground"> @drawable/myenglishviolettheme_edit_text_holo_light </item> 中的文件类似于此drawable

myenglishviolettheme_edit_text_holo_light.xml

您可能希望更改<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/myenglishviolettheme_textfield_default_holo_light" /> <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/myenglishviolettheme_textfield_disabled_holo_light" /> <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/myenglishviolettheme_textfield_activated_holo_light" /> <item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/myenglishviolettheme_textfield_focused_holo_light" /> <item android:state_enabled="true" android:drawable="@drawable/myenglishviolettheme_textfield_default_holo_light" /> <item android:state_focused="true" android:drawable="@drawable/myenglishviolettheme_textfield_disabled_focused_holo_light" /> <item android:drawable="@drawable/myenglishviolettheme_textfield_disabled_holo_light" /> </selector> 资源以符合您的要求