ListView listView = (ListView) findViewById(R.id.listView);
View v = listView.getChildAt(0);
Typeface typeface = Typeface.createFromAsset(getAssets(), "a.ttf");
((TextView) v).setTypeface(typeface);
它有什么问题?
答案 0 :(得分:1)
您不能像这样设置自定义字体列表视图。首先,您需要为列表视图创建自己的自定义适配器。您需要在自定义适配器的getView
方法中设置自定义字体。例如:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if(v == null)
{
LayoutInflater li = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.list_item, null);
}
// Setting custom font to text view
TextView titleText = (TextView) v.findViewById(R.id.title);
Typeface typeface = Typeface.createFromAsset(getAssets(), "a.ttf");
titleText.setTypeface(typeface);
// Do other stuffs
return v;
}