2

I am using a custom font named AwesomeFont in Android App. This help us to produce scalable vector icon. Now the font file get applied on the view (both TextView and EditText) if the application launches from beginning but if the application is in background and get open after few minutes the font-file from the views get removed.

I also try to set typeface from onResume() method but it doesn't help me to get rid of the problem.

Please suggest a solution.

I found that that this problem exist for every custom font that I am using in the application. Custom font get applied throughout the application if is starts from launcher-icon(splash screen), but not if app launches from background after few minutes.

GouravJn
  • 246
  • 1
  • 6
  • 18

1 Answers1

7

1- Copy fontawesome-webfont.ttf into my assests folder

2-Create an entry in strings.xml for each icon. Eg for a fa-bell:

 <string name="bell">&#xf0f3;</string>

3-create entry in the view of my xml layout:

  <Button
 android:id="@+id/bells"
 style="?android:attr/buttonStyleSmall"
 ...
 android:text="@string/bell" />

4-Loaded the font in my onCreate method and set it for the appropriate Views:

   Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome-webfont.ttf" );

    Button button = (Button)findViewById( R.id.bells);
    button.setTypeface(font);

For more See this

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
  • I did the same as you told here except step-5. Actually the I create the Typeface variable in the Application file only and uses it on every activity of the application. – GouravJn Apr 22 '15 at 11:19
  • copy & paste. this answer is exactly same from this link: http://stackoverflow.com/questions/15210548/how-to-use-a-icons-and-symbols-from-font-awesome-on-native-android-application#15762875 @AdityaVyas-Lakhan : you should refer the link – Shoshi Nov 16 '16 at 11:52