-2

I want set font family to Textview

But i want this action before load xml

My code :

for(int i=0;i++;i<100000){    
    final View addNew = G.inflater.inflate(R.layout.post, null);
    TextView txtTitle = (TextView) addNew.findViewById(R.id.txtTitle);
    txtTitle.setText("" + i);
    txtTitle.setTypeface(Typeface.createFromAsset(context.getAssets(),"tahoma.ttf"));
}

This code it takes time 15-16 seconds

But if i not use setTypeface takes time 2-3 seconds

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
Mohammad
  • 111
  • 2
  • 13

2 Answers2

1

You can use the binding. Look at the link

ugurcmk
  • 702
  • 6
  • 10
0

If you don't mind using third party libraries, I recommend you to try Calligraphy. You can find everything you need on the GitHub page, it's really easy to use.

You just need to set it up in your Application class and Activity classes, you put your fonts in the assets folder, and then you can use the fonts from XML, like this:

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fontPath="fonts/Roboto-Bold.ttf"/>
Suppoze
  • 16
  • 2