Reputation: 6575
I'm looking to implement a font picker for my Android app. I already found some nice color pickers, can anybody point me to an example of a font picker that I can pop into my app?
Upvotes: 3
Views: 5080
Reputation:
This looks promissing:
Enumerating the fonts on Android platform
http://www.ulduzsoft.com/2012/01/enumerating-the-fonts-on-android-platform/
FontPreference dialog for Android
http://www.ulduzsoft.com/2012/01/fontpreference-dialog-for-android/
Upvotes: 1
Reputation: 20319
It should be pretty simple to make one using a ListView. Each row in the list could simply be a TextView where the text is set to the name of the font and the typeface used is the actual font.
There doesn't need to be anything special about the listview. A simple listview with an ArrayAdapter should be sufficient. Using an adapter like this should work.
NOTE this code isn't meant to compile rather to illustrate what you would need to do to solve the problem. It should be enough though to get you started.
public class FontListAdapter extends ArrayAdapter< String >
{
public FontListAdapter(Activity context, String[] title, boolean[] isHeader) {
super(context, R.layout.listitem, title);
this.context = context;
this.isHeader = isHeader;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
TextView t;
if (convertView==null)
t = new TextView(parent.getContext());
else
t = (TextView) convertView;
t.setText(getFontName());
t.setTypeface(getFont());
return convertView;
}
public Typeface getFont(int pos){
TypeFace tf = getTypeFaceForThisPosition(pos); // you need to figure this out
return tf;
}
public String getFontName(int pos){
String fontName = getFontNameForThisPosition(pos); // you need to figure this out
return FontName;
}
}
Also you can look at this: http://www.netmite.com/android/mydroid/1.0/development/apps/FontLab/src/com/android/fontlab/FontPicker.java
Upvotes: 1