gpt4 book ai didi

用于自定义字体的 Android 微调器

转载 作者:搜寻专家 更新时间:2023-11-01 08:59:23 24 4
gpt4 key购买 nike

我遇到了问题,我想在下面的编码中为 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) {
}
});
}

最佳答案

您可以通过自己的自定义 SpinnerAdaptergetView()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;
}

关于用于自定义字体的 Android 微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16411131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com