Reputation: 41
I just want change font for my whole application. i just want to have 3 kind of fonts in my asset and when user click my setting it change whole font. I found some example but i cant understand the way . I just new with android.
Upvotes: 1
Views: 67
Reputation: 1974
That library looks quite nice but if you don't know pretty well how use it or you think is too difficult use it you can follow next steps:
In your project, create a folder called "assets" in the same level than res, src, etc...
Inside of this folder create another folder called "fonts" and copy in it the fonts that you need to use...in my case... Robot-Regular.ttf
I think the most used kind of file is *.ttf
Ok, I am not sure if you know create one class which extend from the class Application (if not, check it in internet because it is really important).
In your Application class of your project include:
private static Typeface primaryFont;
/**
* @return primary font Typeface
*
* By keeping only one instance of the typeface, the app performance is increased massively!
*/
public static Typeface getPrimaryFontTypeface() {
if(primaryFont == null){
primaryFont = Typeface.createFromAsset(CameraManager.getContext().getAssets(), Constants.PRIMARY_FONT_PATH);
}
return primaryFont;
}
After in whatever place where you want to use this custom font you will need to set the typeface, by example, to one TextView:
TextView email = (TextView) root.findViewById(R.id.email_tv);
email.setTypeface(getApp().getPrimaryFontTypeface());
If you don't want to write these lines of code everytime that you want to use this custom font, you will need to create a CustomTextView. To create a custom view where you can modify the normal behaviour of that view, you will need to create another question on stackoverflow.
Hope to be helpful. If it is, please score my answer. Thanks! ;)
Upvotes: 0
Reputation: 1233
You should use Calligraphy library, the most easy way to change the fonts in android.
Upvotes: 2