Reputation: 179
How to give a user the ability to select a font? In "preferences", I want to have change Font and there list of fonts.
I have set the font in this way:
mTimerLabel = (TextView)findViewById(R.id.label);
Typeface typeface = Typeface.createFromAsset(getAssets(), "Fonts/digital-7i.ttf");
mTimerLabel.setTypeface(typeface);
Upvotes: 4
Views: 366
Reputation: 12685
store the font name i.e. digital-7i.ttf in the preferences, when user will select any font you can replace the name from preferences and use your code like this.
SharedPreferences Settings = getSharedPreferences(
"<PREF_NAME>", MODE_PRIVATE);
fontName = Settings.getString("<KEY>", "digital-7i.ttf");
mTimerLabel = (TextView)findViewById(R.id.label);
Typeface typeface = Typeface.createFromAsset(getAssets(), "Fonts/"+fontName);
mTimerLabel.setTypeface(typeface);
Upvotes: 1
Reputation: 3846
You will have to store the ttf in your assets folder. Also, AFAIK you cannot name any folder in uppercase chaacters- the way you have done in Fonts
. Rest of the approach is fine. You might want to check the value you are storing in preferences using Logcat.
Upvotes: 2
Reputation: 200
You've described the correct model of changing typeface in textView. I can't understand the problem you've faced. Call preferences for a textView, choose font (or its id) and set it.
Upvotes: 2