更改列表片段的字体,细节片段 [英] Change font of list fragment on Detail fragment
问题描述
我想使用的Android 4.0来实现片段。
我已经加入列表中的片段中的三个项目在我DummyContent.java文件
I am trying to implement fragment using android 4.0. I have added the three items in list fragment in my DummyContent.java file
static {
// Add 3 sample items.
addItem(new DummyItem("1", "Videos"));
addItem(new DummyItem("2", "Images"));
addItem(new DummyItem("3", "Story"));
}
这些视频,图像,故事都出现在每个项目它的点击片段的左侧显示在右侧的细节片段细节信息。
These Videos,Images,Story are appearing on left side of fragment on click of each it item shows details information on detail fragment in right hand side.
我要改变这些列表视图的字体,但问题是列表片段使用系统的TextView如下
I want to change the font of these list views but problem is list fragment uses systems textview as below
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: replace with a real list adapter.
setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1, DummyContent.ITEMS));
}
这是不是让我申请到字样 android.R.id.text1
请帮我
推荐答案
一个办法是延长 ArrayAdapter
并重写 getView
方法得到的保持在的TextView
:
One way to is to extend ArrayAdapter
and override the getView
method to get a hold of the TextView
:
public class MyArrayAdapter<T> extends ArrayAdapter<T> {
public MyArrayAdapter(Context context, List<T> items) {
super(context, android.R.layout.simple_list_item_activated_1, android.R.id.text1, items);
}
public MyArrayAdapter(Context context, T[] items) {
super(context, android.R.layout.simple_list_item_activated_1, android.R.id.text1, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "font/segoeuil.tff"));
return view;
}
}
您会然后设置您的适配器像这样:
You would then set your adapter like so:
setListAdapter(new MyArrayAdapter<DummyContent.DummyItem>(getActivity(), DummyContent.ITEMS);
这篇关于更改列表片段的字体,细节片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!