android - How to use font icon (font-awesome) in XML selector -


is possible use font icon in selector instead of drawable ?

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

i changed text color in selector instead of drawable. working fine.

create mytextview class 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 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" />     <!-- pressed -->     <item android:color="#ff0000" android:state_focused="true" />     <!-- focused -->     <item android:color="#000000" />     <!-- default --> </selector> 

and use in 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> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -