在android的listview中将字体设置为文本
我想将列表视图的字体设置为araliya.ttf。这是我的密码。没有错误,但listview文本中的字体没有更改。(它在文本视图和按钮中更改)有人能告诉我这里出了什么问题吗。谢谢在android的listview中将字体设置为文本,android,android-listview,android-typeface,Android,Android Listview,Android Typeface,我想将列表视图的字体设置为araliya.ttf。这是我的密码。没有错误,但listview文本中的字体没有更改。(它在文本视图和按钮中更改)有人能告诉我这里出了什么问题吗。谢谢 public class MyCustomAdapter extends ArrayAdapter<Item> { private ArrayList<Item> itemList; Typeface tf; public MyCustomAd
public class MyCustomAdapter extends ArrayAdapter<Item> {
private ArrayList<Item> itemList;
Typeface tf;
public MyCustomAdapter(Context context, int textViewResourceId,
ArrayList<Item> itemList) {
super(context, textViewResourceId, itemList);
this.itemList = new ArrayList<Item>();
this.itemList.addAll(itemList);
// tf = Typeface.createFromAsset(context.getAssets(), "araliya.ttf");
}
private class ViewHolder {
TextView code;
CheckBox name;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.symptom_info, null);
sinfont = Typeface.createFromAsset(getAssets(), "araliya.ttf");
holder = new ViewHolder();
holder.code = (TextView) convertView.findViewById(R.id.code);
holder.code.setTypeface(sinfont);
holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1);
holder.name.setTypeface(sinfont);
convertView.setTag(holder);
这非常有效,可以更改textview中文本的字体。我敢肯定,您没有正确设置路径
Typeface sinfont = Typeface.createFromAsset(getAssets(), "araliya.ttf");
这里araliya.ttf不是正确的路径。它应该是font/araliya.ttf
实际上createFromAsset中的seconds参数代表字体的路径。因此,如果您将字体放在资产/字体中。下面是初始化字体所需的代码
String path = "fonts/araliya.ttf"
Typeface sinfont = Typeface.createFromAsset(getAssets(), path);
然后您可以使用
holder.code.setTypeface(sinfont);
您是否已将typeface.ttf文件添加到Assets/fonts?是的,我添加了该文件。所有文本视图和按钮文本,甚至微调器文本中的字体都会更改。但它在listview中没有更改。请帮忙!我已经补充了答案。这是因为您没有设置正确的字体路径。我在资产文件夹中有araliya.ttf。TextView t1=(TextView)findViewById(R.id.textView2);t1.设置字体(sinfont);t1.setText(“我的,ska m%fNoh f;dard.kak”);这非常有效,可以更改textview中文本的字体。然后尝试将其更改为fonts文件夹。如果仍然不起作用,则使用其他字体进行测试试用。如果您已解决问题,请用答案更新您的问题。
String path = "fonts/araliya.ttf"
Typeface sinfont = Typeface.createFromAsset(getAssets(), path);
holder.code.setTypeface(sinfont);