I changed the color of the text in the selector instead of drawable. His work is wonderful.
Create a class MyTextView that extends TextView
public class MyTextView extends TextView { public MyTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public MyTextView(Context context) { super(context); init(context); } private void init(Context context) { Typeface tf = Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf"); setTypeface(tf); } }
Create a text_color_selector.xml selector
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="#ff0000" android:state_pressed="true" /> <item android:color="#ff0000" android:state_focused="true" /> <item android:color="#000000" /> </selector>
And then use it in your layout
<com.example.mohsin.myapplication.MyTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="50sp" android:clickable="true" android:textColor="@drawable/text_color_selector" android:text="\uF242"> </com.example.mohsin.myapplication.MyTextView>
source share