I created a sample application using Android TextView with shared preferences. In my application i have a sample textview which contains some text (Eg. “Android Font Text”), and also a had set of fonts in my assets folder. Here my requirement is, when i touch the textview, a sample dialog will popup in this pop up i shows the list of font’s in assets folder. When i select any one of the font it was changed successfully, it persist only in that particular activity. When i back to next activity the text view remains in default style. Here how can i achieve shared preferences for fonts. I can’t pass the type face object through the editor. I used like this,
Typeface font = Typeface.createFromAsset(getAssets(),"digit_fonts/AKEI____.TTF");
font.isBold();
mTextView.setTypeface(font);
font_editor = font_pref.edit();
font_editor.putString("font_style", font.toString());
font_editor.commit();
Unfortunately it won’t works, how can i acheive, if any one solve my problem. Thanks in Advance.
So, you’re trying to load a font from sharedpreferences whenever an activity is started?
If I’m understanding you correctly, what you need to do is
1) Save the file name of the font the user has chosen (i.e., “digit_fonts/AKEI__.TTF”)
2) Load the font using the file name saved in shared preferences, for example:
Then apply the font as you normally would.
EDIT:
To load:
To save:
As you can see, font_style is actually the file location of your font (the way I’ve coded it above). When the user chooses a font, you alter font_style then save it to preferences.