java - Unable to change default font in Android app -


i trying change default font in app. not working. these steps have taken:

1) created class typefaceutil.java

import android.content.context; import android.graphics.typeface; import android.util.log;  import java.lang.reflect.field;  public class typefaceutil {  public static void overridefont(context context, string defaultfontnametooverride, string customfontfilenameinassets) {     try {         final typeface customfonttypeface = typeface.createfromasset(context.getassets(), customfontfilenameinassets);          final field defaultfonttypefacefield = typeface.class.getdeclaredfield(defaultfontnametooverride);         defaultfonttypefacefield.setaccessible(true);         defaultfonttypefacefield.set(null, customfonttypeface);     } catch (exception e) {         log.e("customfontexception", "can not set custom font " + customfontfilenameinassets + " instead of " + defaultfontnametooverride);     }   } } 

2) in class extending application:

public void oncreate() {       super.oncreate();      typefaceutil.overridefont(getapplicationcontext(), "monospace", "fonts/varelaround_regular.ttf");  } 

3) in styles.xml

 <style name="apptheme" parent="theme.appcompat.light.darkactionbar">      <item name="android:typeface">monospace</item>  </style> 

still not working. missing ?

i had faced problem once. not sure why works, can try following : instead of "monospace", try each of these: default, sans_serif, serif. might not work textviews, in listview or recyclerview (weird, right?). in cases, set typeface programatically adapter. sorry unable explain reason.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -