xml - Android: textColor of disabled button in selector not showing? -


i trying make button selector button can have following states:

  • enabled/disabled
  • pressed/not pressed

according states mentioned above. need manipulate button's:

  • text color
  • background image

the button starts off being disabled should have disabled textcolor , disabled button background. can see default textcolor (specified in style) , no background image!

here selector button_selector.xml

<?xml version="1.0" encoding="utf-8"?>  <selector xmlns:android="http://schemas.android.com/apk/res/android">      <item android:state_pressed="false"         android:state_enabled="false"         android:textcolor="#9d9fa2"         android:drawable="@drawable/button" />          <item android:state_pressed="true"         android:state_enabled="true"         android:drawable="@drawable/button_pressed"/>      <item android:state_pressed="true"         android:state_enabled="false"         android:textcolor="#9d9fa2"         android:drawable="@drawable/button"/>      <item android:state_pressed="false"         android:state_enabled="true"         android:drawable="@drawable/button"/>      </selector> 

and here button declaration in layout.xml

    <button android:id="@+id/reserve_button"         android:text="@string/reserve_button"         android:layout_width="120dp"         android:layout_height="40dp"         android:layout_margintop="10dp"         android:layout_marginleft="20dp"         android:paddingright="15dp"         android:layout_gravity="left"         style="@style/buttonstyle"         android:background="@drawable/button_selector" /> 

and style (where default textcolor set)

<?xml version="1.0" encoding="utf-8"?>   <resources>       <style name="buttonstyle">       <item name="android:textstyle">bold</item>       <item name="android:textcolor">#282780</item>       <item name="android:textsize">18sp</item>      </style>  </resources> 

please help!

you need create colorstatelist text colors identifying different states.

do following:

  1. create xml file in res\color named text_color.xml.

    <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">   <!-- disabled state -->   <item android:state_enabled="false" android:color="#9d9fa2" />    <item android:color="#000"/> </selector> 
  2. in style.xml, put reference text_color.xml file follows:

    <style name="buttonstyle">   <item name="android:textstyle">bold</item>   <item name="android:textcolor">@color/text_color</item>   <item name="android:textsize">18sp</item> </style> 

this should resolve issue.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -