如何在安卓中更改EditText提示字体?

4

如我在问题中提到的,我想要改变EditText中提示字体的样式,但似乎无法实现!

以下是获取用户名的EditText代码:

<!-- Email Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:id="@+id/input_username_id"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="20dp">

            <EditText
                android:id="@+id/input_username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:hint="@string/hint_username"
                android:layout_marginRight="10dp"
                android:gravity="right" />
        </android.support.design.widget.TextInputLayout>

以下是我的Java代码:

_usernameText = (EditText) (findViewById(R.id.input_username));
font = Typeface.createFromAsset(getAssets(), "fonts/ir.ttf");
_usernameText.setTypeface(font);

这没有改变EditText提示的字体。 我尝试了其他解决方案,但仍然没有改变。 http://chintanrathod.com/customizing-textinputlayout-part-2/

2个回答

7

不要这样做

  _usernameText = (EditText) (findViewById(R.id.input_username));
 font = Typeface.createFromAsset(getAssets(), "fonts/ir.ttf");
 _usernameText.setTypeface(font);

TextInputLayout   usernameTextObj = (TextInputLayout)    findViewById(R.id.input_username_id));
font = Typeface.createFromAsset(getAssets(), "fonts/ir.ttf");
usernameTextObj .setTypeface(font);

2

由于您的EditText被包裹在TextInputLayout中,因此您需要在TextInputLayout对象引用上设置setTypeface。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接