选择器在Textview中不起作用,用于将textColor更改为禁用状态

时间:2015-08-12 11:30:25

标签: android-layout

即使禁用了textView,我也希望textColor为黑色。为此,我使用一个选择器,但它没有工作,它给我默认灰色文本颜色处于禁用状态。 选择器文件如下:

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

设置选择器的TextView如下:

  <com.rengwuxian.materialedittext.MaterialTextView
         android:id="@+id/policyEndDateText"
         style="?android:attr/spinnerStyle"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="8dp"
         android:textColor="@color/textview_color_selector"
         android:enabled="false"
         android:hint="New Policy End Date"
         android:textSize="@dimen/insurance_text_size"
        app:met_floatingLabelTextSize="@dimen/insurance_floating_label_textSize"
          app:met_hideUnderline="true"
          app:met_floatingLabel="highlight"
          app:met_primaryColor="@color/material_text"/>

1 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/colorPrimary_purple"/>
    <item android:drawable="@color/colorAccent_purple" android:state_pressed="true"/>
    <item android:drawable="@color/colorAccent" android:state_focused="true"/>
</selector>