First, create a new XML file in your res/layout directory called "my_spinner_style.xml", and put in something like the following content:
Then in your code, use something like this:android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="9pt"
android:singleLine="True"
android:id="@+id/spinnerTarget"
android:textColor="#000000"
android:gravity="center"/>
Spinner mySpinner = (Spinner) findViewById(R.id.my_spinner);Normally you would create a new ArrayAdapter for the second line, but in this case you need to create a custom ArrayAdapter and override the methods that get the TextView from our custom spinner style.
mySpinnerArrayAdapter = new MyCustomArrayAdapter(this, R.layout.my_spinner_style); mySpinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
So, you need to put in the code for your custom ArrayAdapter, like so:
private class MyArrayAdapter extends ArrayAdapterThe font you want to use needs to reside in the assets/fonts directory, and you access it like so:{
public MyArrayAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public TextView getView(int position, View convertView, ViewGroup parent) {
TextView v = (TextView) super.getView(position, convertView, parent);
v.setTypeface(myFont);
return v;
}
public TextView getDropDownView(int position, View convertView, ViewGroup parent) {
TextView v = (TextView) super.getView(position, convertView, parent);
v.setTypeface(myFont);
return v;
}
}
Typeface myFont = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");And that's pretty much it. I always appreciate it when I'm having a problem and I Google around and find in someone's blog that they've already dealt with the same issue, so I hope this helps someone.