I was trying to add custom font to Preference Fragment. I tried everywhere but i couldn't solve it. Can anybody suggest me the best possibilities i can do it. Thanks in advance.
Asked
Active
Viewed 918 times
2 Answers
1
A long solution is to create custom preferences for each Preference and to apply the font in the onBindViewHolder
of the preference. It is long but it works : with this you have a complete control on your Preference object.
-1
For adding custom fonts you need to place the font in your assets directory and the set typeface programmatically for every view that is going to use that font. Wihout using exteral library like calligraphy you cannot set typeface in your xml. For a Roboto-Light.ttf file stored in assets directory you can do something like this in your onCreateView of PreferenceFragment:
Typeface custom=Typeface.createFromAsset(getAssets(),
"Roboto-Light.ttf");
textView.setTypeFace(custom);

Illegal Argument
- 10,090
- 2
- 44
- 61
-
1I can comment in their stead to point out that you didn't answer the question at all. It's not a matter of "how to find a font", but rather there's no obvious interface for setting the font for a preference screen. – Zac Sweers Nov 27 '14 at 08:38
-
Yeah this is an open issue, there is no direct interface to the views in the `PreferenceFragment`. This is an open issue for me, tieing into the layoutinflater is probably the only plausible sane DRY solution. – Chris.Jenkins Feb 25 '15 at 12:04
-
You can change the theme of PreferenceActivity see here http://stackoverflow.com/questions/2615528/preferenceactivity-and-theme-not-applying and apply calligraphy to the changed theme – Illegal Argument Feb 26 '15 at 03:15