Android selects custom fonts

How to give the user the opportunity to choose a font? In "preferences," I want to change the font and font list.

I set the font like this:

mTimerLabel = (TextView)findViewById(R.id.label); Typeface typeface = Typeface.createFromAsset(getAssets(), "Fonts/digital-7i.ttf"); mTimerLabel.setTypeface(typeface); 
+4
source share
3 answers

You have described the correct font change model in textView. I can not understand the problem you are facing. Call the settings for textView, select the font (or its identifier) ​​and set it.

+2
source

You will need to save ttf in the folder with your resources. Also, AFAIK you cannot name any folder in uppercase characters, as you did in Fonts . The rest of the approach is beautiful. You can check the value that you save in the settings using Logcat.

+2
source

save the font name ie digital-7i.ttf in the settings, when the user selects any font that you can replace with the name from the settings, and use your code as follows.

 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); 
+1
source

Source: https://habr.com/ru/post/1437587/


All Articles