简体   繁体   中英

Change font of String / ListPreference Android

I have a ListPreference which I use to select fonts. In the ListPreference, I want to change the font of different font names. My question is related to this - I want to change font of string without using textview in android but this doesn't work for me.
For example (Refer to the picture below) - On the 2nd position is "Monospace". I want to change the font of it to Monospace .

例

The code I use for entries is -

String a = "Default";
String b = "Monospace";
String c = "Unique";
String d = "Architect\'s Daughter";
String e = "Dancing Script";
CharSequence[] cs = {a, b, c, d, e};
ListPreference listPref = (ListPreference) findPreference("font");
listPref.setEntries(cs);

Any ways how I can display the fonts itself on ListPreference?
Thanks for helping.

You need to extend ListPreference class, and override method onCreateDialogView() where you create your own dialog with listview and custom adapter which will handle typeface for each row. Here is example of creating custom preference view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM