我使用bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
然后设置
dropdownValues = getResources().getStringArray(R.array.sortby_array);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.sortby_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
bar.setListNavigationCallbacks(adapter, this);
现在我想改变字体样式..所以任何人都可以帮助我PLZ
答案 0 :(得分:2)
在资源文件夹中创建一个文件夹字体,并将字体放在该文件夹中。希望这对您有用
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.sortby_array, android.R.layout.simple_spinner_item) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
Typeface externalFont=Typeface.createFromAsset(getAssets(), "fonts/your font name here");
((TextView) v).setTypeface(externalFont);
return v;
}
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View v =super.getDropDownView(position, convertView, parent);
Typeface externalFont=Typeface.createFromAsset(getAssets(), "fonts/ your font name here");
((TextView) v).setTypeface(externalFont);
return v;
}
};
答案 1 :(得分:0)
试试这个
mLocations = getResources().getStringArray(R.array.locations);
Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
创建此R.layout.sherlock_spinner_dropdown_item
答案 2 :(得分:0)
我用SpinnerAdapter
完成了这项工作。参见代码示例:
public class SpinnerAdapter extends ArrayAdapter<String> {
public SpinnerAdapter(Context context, int textViewResourceId,
String[] strings) {
super(context, textViewResourceId, strings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (view instanceof TextView) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"fonts/hattori.ttf");
((TextView) view).setTextColor(Color.parseColor("#000000"));
((TextView) view).setTypeface(tf);
((TextView) view).setTextSize(16);
}
return view;
}
}
编辑:这不在ActionBar中,所以不确定它是否有效。