繁体   English   中英

如何更改ListView的字体?

[英]How can I change the font of ListView?

我需要一些有关如何更改ListView字体的帮助。 我已经搜索并签出了一些答案,但我不太了解。

我已经通过使用以下代码成功更改了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);

    }

但是我想更改ListView元素的字体,有没有办法像上面提到的那样呢?

您必须使用自定义listView适配器。 您可以在该适配器中更改字体。 检查此站点以了解如何使用自定义适配器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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM