customization - Custom font not working at runtime in Android -


i made custom textview load font (in case icomoon font). custom textview class looks below:

public class customtextview extends textview {      public customtextview(context context) {         super(context);         init(context);     }      public customtextview(context context, attributeset attrs) {         super(context, attrs);         init(context);     }      public customtextview(context context, attributeset attrs, int defstyleattr) {         super(context, attrs, defstyleattr);         init(context);     }      @suppresswarnings("newapi")     public customtextview(context context, attributeset attrs, int defstyleattr, int defstyleres) {         super(context, attrs, defstyleattr, defstyleres);         init(context);     }      /**      * load , apply font widget      *      * @param context initialize      */     private void init(context context) {         typeface font = typeface.createfromasset(context.getassets(), "icomoon.ttf");         if(font != null)             settypeface(font);     } } 

in layout file, used class below:

<com.test.customtextview     android:id="@+id/txt_about_hotel_icon"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="&#xe020;"     android:textappearance="?android:attr/textappearancelarge"     android:textcolor="@color/textcolorprimary" /> 

everything goes when use class in layout , set text display font icon. problem begins when try use class in activity class set font icon below:

customtextview txthotelicon = (customtextview) findviewbyid(r.id.txt_about_hotel_icon); txthotelicon.settext("&#xe020;"); 

now problem is, if set font character in xml layout, works great , font icon visible. when try set font text value @ run-time, shows exact text instead of showing font icon.

please suggest me how fix issue.

as far know textview doesn't support html notation directly, try 1 of following:

  • load text using settext(html.fromhtml("&#xe020;"))
  • replace html notation unicode settext("\ue020")

haven't tried icon fonts yet, might not work.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -