Android自定义字体渲染问题
问题描述:
我正在尝试更改我的listview字体。我创建了assets/fonts
文件夹。我在此文件夹中添加了OpenSans-Regular.ttf
。我在我的Adapter类中添加了typeface
行。 适配器:Android自定义字体渲染问题
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模拟器上的 – Jonas
。 @Jonas – heyaa
请注意,仿真器在正确渲染图形时遇到麻烦。我强烈建议您在物理设备上运行应用程序。 – Jonas