[英]How can I change the font of ListView?
I need some assistance on how to change my ListView
font. 我需要一些有关如何更改ListView
字体的帮助。 I have searched and checked out some answers but I don't really understand it. 我已经搜索并签出了一些答案,但我不太了解。
I have successfully changed the TextView by using the following code: 我已经通过使用以下代码成功更改了TextView:
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/roboto.ttf");
setTypeface(tf ,1);
}
But I want to change the ListView
element font, is there any way to do it like mentioned above? 但是我想更改ListView
元素的字体,有没有办法像上面提到的那样呢?
you have to use a custom listView adapter. 您必须使用自定义listView适配器。 and you can change the font in that adapter. 您可以在该适配器中更改字体。 Check this site to know how to use custom adapter http://www.vogella.com/tutorials/AndroidListView/article.html 检查此站点以了解如何使用自定义适配器http://www.vogella.com/tutorials/AndroidListView/article.html
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
Your_Class_Name.this,
android.R.layout.simple_list_item_multiple_choice, Your_Array_List) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
CheckedTextView textView = (CheckedTextView) view
.findViewById(android.R.id.text1);
// You do here whatever you want with textView
return view;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.