Android - Selector does not work for text in button -
using android studio. i'm trying utilize selector create text in button turn white dark gray. text, not background of button.
here selector xml:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/darker_gray" android:state_pressed="true"></item> <item android:drawable="@android:color/white" android:state_focused="true"></item> <item android:drawable="@android:color/white" android:state_enabled="true" android:state_focused="false" android:state_pressed="false"></item> <item android:drawable="@android:color/white" android:state_enabled="false"></item> </selector>
and here button xml:
<button android:layout_width="match_parent" android:layout_height="45dp" android:text="maps" android:id="@+id/buttonmaps" android:layout_above="@+id/buttonemail" android:layout_marginbottom="5dp" android:layout_centerhorizontal="true" android:textcolor="@drawable/selector" <------- **selector not working** android:background="#7f2f74a0" <------- **but work if stick here** android:textsize="20sp" />
in preview panel, receive rendering error message reads, "failed configure parser /users...src/main/res/drawable/selector.xml"
i've tried number of solutions so, , nil has worked, including cleaning , rebuilding project. interestingly, got curious , applied selector button's background , works - button background defaults white , changes grayness when pressed.
anyone smarter have solution this?
thanks!
put text selector in color folder under resources instead of drawable.
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@android:color/darker_gray" android:state_pressed="true"></item> <item android:color="@android:color/white" android:state_focused="true"></item> <item android:color="@android:color/white" android:state_enabled="true" android:state_focused="false" android:state_pressed="false"></item> <item android:color="@android:color/white" android:state_enabled="false"></item> </selector>
and utilize like,
<button android:layout_width="match_parent" android:layout_height="45dp" android:text="maps" android:id="@+id/buttonmaps" android:layout_above="@+id/buttonemail" android:layout_marginbottom="5dp" android:layout_centerhorizontal="true" android:textcolor="@color/selector" android:textsize="20sp" />
android button textcolor
No comments:
Post a Comment