禁用editText但使用不同的颜色

时间:2013-08-27 13:27:06

标签: android user-interface android-edittext

<EditText
    android:id="@+id/myEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:enabled="false" >
</EditText>

我有上面禁用的编辑文字。我只从其他地方获取值并将其插入其中,用户无法在其中键入。但是,处于禁用状态时编辑文本的颜色太灰,有时对用户不可见。我更喜欢它看起来是黑色的。是否有任何我不知道的基本功能可以在禁用模式下更改编辑文本的颜色? 任何其他工作也都可以。

3 个答案:

答案 0 :(得分:3)

您的布局:

<EditText
    android:id="@+id/myEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:enabled="false"
    android:background = "@drawable/edittextdrawable.xml">
</EditText>

<强> edittextdrawable.xml:

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:state_enabled="false"
                android:drawable="@drawable/PUT DRAWABLE HERE" />
            <item android:state_enabled="true"
                android:drawable="@drawable/PUT DRAWABLE HERE" />
 </selector>

答案 1 :(得分:0)

如果您不希望用户输入,则应使用TextView。然后你不需要使用disable来阻止用户输入它。

答案 2 :(得分:0)

尝试使用statelist xml drawable,并将其设置为EditText的背景:

   <?xml version="1.0" encoding="utf-8"?>   <selector xmlns:android="http://schemas.android.com/apk/res/android">      <item android:state_pressed="true"
                  android:drawable="@drawable/bankszamlak_pressed" />  <!-- pressed -->     <item android:state_focused="true"
                  android:drawable="@drawable/bankszamlak" />  <!-- focused -->     <item android:drawable="@drawable/bankszamlak" />  <!-- default -->  </selector>

有关详细信息,请查看this link