MyNameIsAsker MyNameIsAsker - 3 months ago 15
Android Question

Android - Button's textColor with a selector not working

I am trying to use a selector as button's textColor. But, for some reasons, the textColor becomes pink. I've searched a lot but couldn't find any solution for this case.

main_button_text_color.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@android:color/black"/>
<item android:state_pressed="true" android:drawable="@android:color/black"/>
<item android:drawable="@android:color/white"/>
</selector>


Button

<Button
android:id="@+id/btnRegister"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginBottom="15dp"
android:background="@drawable/main_button_background"
android:text="register"
android:textColor="@drawable/main_button_text_color" />


the result : Button Image

Answer

Try this one:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="@android:color/black"/>
    <item android:state_pressed="true" android:color="@android:color/black"/>
    <item android:color="@android:color/white"/>
</selector>