我无法在Spinner中设置下拉项目的字体!
我尝试过的代码是:
public class MainActivity extends Activity {
fontadapter fa;
TextView spinner_text;
Activity temp;
String[] spin_val;
Spinner language;
Locale myLocale;
View parent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spin_val = new String[10];
spin_val[0] = "english";
spin_val[1] = "portugese";
spin_val[2] = "spanish";
fa = new fontadapter(MainActivity.this, R.layout.my_spinner_text,spin_val);
language = (Spinner) findViewById(R.id.languagespinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.languages, R.layout.my_spinner_text);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
language.setAdapter(adapter);
//language.setAdapter(fa);
language.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
fa.getView(pos, view, parent);
if (pos == 1) {
setLocale("en");
} else if (pos == 2) {
setLocale("po");
} else if (pos == 3) {
setLocale("sp");
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
private class fontadapter extends ArrayAdapter {
Typeface tf = Typeface.createFromAsset(getAssets(), "mafw.ttf");
public fontadapter(Context context, int textViewResourceId,String[] a) {
super(context, textViewResourceId,a);
}
public View getView(int pos, View convertView, ViewGroup parent) {
if (pos == 1) {
setLocale("en");
} else if (pos == 2) {
setLocale("po");
} else if (pos == 3) {
setLocale("sp");
}
View v = super.getView(pos, convertView, parent);
Typeface externalFont=Typeface.createFromAsset(getAssets(), "mafw.ttf");
((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(), "mawf.ttf");
((TextView) v).setTypeface(externalFont);
return v;
}
}
public void setLocale(String lang) {
myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent i = new Intent(MainActivity.this, Lovername.class);
startActivity(i);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
}
我尝试了很多在SO中实现的方法,任何人都可以指出我的错误!
代码中没有错误,我唯一想要的是设置Drop Down微调器的字体。
由于