Reputation: 157
Here is my problem :
I want to be able to change the font of several TextView at the same time in my android application.
Changing it in the XML files seems to be complicated, extending TextView class brings memory problems (see here).
So i tried to change the font in the java code, like that :
Typeface robotoThin = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Thin-webfont.ttf");
TextView index_slogan = ((TextView)findViewById(R.id.index_slogan));
index_slogan.setTypeface(robotoThin);
That's working great, but i'd rather to select more than one Textview, with findViewsWithText
, but i can't understand how it works...
Some help would be appreciated.
EDIT :
Ok so it didn't work because it's been implemented since API level 14, and i was trying on API level 10...
Do you know any other functions to find multiple views?
Upvotes: 4
Views: 5185
Reputation: 2927
1- how to set Costume font ,the best way to set costume font is to do that programmatically and the best and easier way to do that , register public
static
Typeface
in ur Api or main class for example I've Api.class
content every costume things i made
add
public static Typeface myfont;
then when i call the Api.class
on my activity creation set the font type
Api.myfont = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Thin-webfont.ttf");
now you can use Api.myfont
for every textview or Edittext or any other views for example
editText.setTypeface(Api.myfont);
myradio.setTypeface(Api.myfont);
mytextview.setTypeface(Api.myfont);
mycheckBox.setTypeface(Api.myfont);
2 - findViewsWithText()
will fetch the view's has android:contentDescription="blabla"
Upvotes: 2
Reputation: 3028
The easiest way to do this is to create a custom TextView
and in to set the font there. That way you can even create custom styleables, that define what font to use.
Take a look at this answer on how the view should look and this documentation about custom styleables.
Upvotes: 0