如何更改默认禁用的EditText的样式?

时间:2013-05-02 11:35:58

标签: android styles android-edittext default

使用EditText enabled =“false”时效果不佳。我怎样才能改变它 自动进行所有控制?

我已添加此图片以供参考。 enter image description here

有人能帮助我吗?感谢。

2 个答案:

答案 0 :(得分:47)

在drawable中创建自定义选择器并将其设置为

<EditText android:textColor="@drawable/edit_text_selector" />

'colors.xml'中的

1)定义启用和禁用状态的颜色:

<color name="enabled_color">#F7FE2E</color>
<color name="disabled_color">#000000</color>
'drawable / edit_text_selector.xml'中的

2)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/disabled_color"/>
    <item android:color="@color/normal_color"/>
</selector>
layout.xml中的

3)

<EditText
    android:id="@+id/customEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:enabled="false"
    android:text="Hello!"
    android:textColor="@drawable/edit_text_selector" />

答案 1 :(得分:41)

在颜色文件中定义颜色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/disabled_color" />
    <item android:color="@color/normal_color"/>
</selector>

在布局中:

<EditText
    android:text="whatever text you want"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/example" />
</EditText>
相关问题