0

我想将列表视图项目的字体更改为马拉地语,我使用字体来更改 TextField 的字体,谁能告诉我如何使用列表视图项目来做到这一点。

4

2 回答 2

2

像这样创建一个自定义 textView 类

public class CustomTextView extends TextView {

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomTextView(Context context) {
        super(context);
        init();
    }

    @SuppressWarnings("null")
    private void init() {
        if (!isInEditMode()) {


            // default style
            Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
                    "helveticaneue_bold.ttf");


            setTypeface(tf);
        }
    }

将您的字体样式(Marathi.ttf 文件,在这种情况下我使用 helveticaneue_bold.ttf )在 assets 文件夹中。

现在在你的行中,你已经膨胀到 ListView ,而不是 TextView 在下面使用

 <yourpackagename.CustomTextView
            android:id="@+id/tv_title"
            style="@style/buttontext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/company_profile" >
        </yourpackagename.CustomTextView>
于 2013-09-27T07:56:56.493 回答
0

您必须实现 CustomAdapter 或 BaseAdapter 才能实现此目的。在 getview 方法中,将包含 textview 和 settypeface 的其他 xml 文件膨胀到它

于 2013-09-27T09:44:41.417 回答