我遇到的问题是我想在以下编码中为android spinner添加自定义字体。我已经尝试过使用ArrayAdapter,但还不能成功。感谢。
private void loadSpinner() {
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");
list.add("6");
list.add("7");
list.add("8");
list.add("9");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cmbStage.setAdapter(dataAdapter);
cmbStage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Object item = parent.getItemIdAtPosition(pos + 1);
currentID = Integer.parseInt(item.toString());
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
答案 0 :(得分:3)
您可以在SpinnerAdapter
和getView()
getDropDownView()
应用字体
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(yourRowlayout, parent,
false);
TextView make = (TextView) row.findViewById(R.id.Make);
Typeface myTypeFace = Typeface.createFromAsset(context.getAssets(),
"fonts/gilsanslight.otf");
v.setTypeface(myTypeFace);
v.setText(itemList.get(position));
return row;
}
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(yourRowlayout, parent,
false);
TextView make = (TextView) row.findViewById(R.id.Make);
Typeface myTypeFace = Typeface.createFromAsset(context.getAssets(),
"fonts/gilsanslight.otf");
v.setTypeface(myTypeFace);
v.setText(itemList.get(position));
return row;
}