【发布时间】:2017-08-07 06:10:47
【问题描述】:
我正在尝试更改我的列表视图字体。我创建了assets/fonts 文件夹。我在这个文件夹中添加了OpenSans-Regular.ttf。我在我的适配器类中添加了typeface 行。
适配器:
public class Adapter extends BaseAdapter {
List<String> listFunds;
Typeface typeface;
Context mContext;
public Adapter(Context mContext, List<String> listFunds) {
this.mContext = mContext;
this.listFunds = listFunds;
}
public int getCount() {
return listFunds.size();
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View arg1, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_row, viewGroup, false);
TextView textView = (TextView) row.findViewById(R.id.textView);
textView.setText(listFunds.get(position));
typeface = Typeface.createFromAsset(mContext.getAssets(), "fonts/"+"OpenSans-Regular.ttf");
textView.setTypeface(typeface);
return row;
}
}
但是,字体看起来不像它应该的那样。我尝试了很多字体,但没有任何改变。
我的应用看起来像这样:
【问题讨论】:
-
您是在物理设备上还是在模拟器上运行应用程序?
-
在 Android 模拟器上。 @乔纳斯
-
请注意,众所周知,模拟器在正确渲染图形方面存在问题。我强烈建议您在物理设备上运行该应用程序。
-
谢谢!问题出在模拟器上。我正在使用 GenyMotion,字体现在看起来不错:) @Jonas