TextInputLayout and EditText double hint issue

后端 未结 7 2278
生来不讨喜
生来不讨喜 2021-02-11 19:34

I want to set the hint with java in EditText(which is in TextInputLayout).

Code used for setting hint:

aET = (EditText) findViewById(R.id.

7条回答
  •  星月不相逢
    2021-02-11 19:48

    This problem occurs because the hint from the xml is passed on to the TextInputLayout, so it can be displayed as a floating hint. But when you set it programatically, the hint is set to the EditText, which then results in two hints (one from the xml that is a floating hint and one you set programatically and is a normal EditText hint). If you wish to change the floating hint, you must set the hint on TextInputLayout.

    You code will then look like this:

    aTIL = (TextInputLayout) findViewById(R.id.aTIL);
    aTIL.setHint("h?");
    

提交回复
热议问题