how to change the font of the EditText hint in and

2019-08-01 11:57发布

As I have mentioned in the Question I am trying to change the font of hint in EditText. But I can't seem to make it happen!

this is my code for the the EditText getting the username:

<!-- 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>

and here is my java code:

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

this didn't change the font of the hint of the EditText. I have tried other solutions and nothing changed. http://chintanrathod.com/customizing-textinputlayout-part-2/

2条回答
虎瘦雄心在
2楼-- · 2019-08-01 12:39

Don't

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

Do

TextInputLayout   usernameTextObj = (TextInputLayout)    findViewById(R.id.input_username_id));
font = Typeface.createFromAsset(getAssets(), "fonts/ir.ttf");
usernameTextObj .setTypeface(font);
查看更多
别忘想泡老子
3楼-- · 2019-08-01 12:53

since your EditText is wrapped in TextInputLayout you will have to setTypeface on TextInputLayout object reference

查看更多
登录 后发表回答