0

Currently, I use TextInputLayout (See) which the hint can float to the top when control is focused. It works well but I cannot setHint to it programmatically when I click on a button.

Here is what I did.

editText1.setHint("Input username");

This is my xml code

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:paddingTop="20dp">

        <EditText
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:id="@+id/user_field"
           android:hint="Enter your User-ID or username"
           android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>

This is control before click button.

enter image description here

After click button

enter image description here

It should change the small red text to Input username.

Thank for any helps.

Community
  • 1
  • 1
K.Sopheak
  • 22,904
  • 4
  • 33
  • 78
  • Thank @MikeM., I will look that the thread. – K.Sopheak Oct 06 '16 at 02:55
  • @MikeM. Correct, It work now. I should marked my question duplicate. But why I cannot use the edittext inside of the TextInputLayout tag to set the hint? In xml, when I can set hint in editText and it work but in code cannot. I have to use from the main tag. – K.Sopheak Oct 06 '16 at 03:07
  • 1
    `TextInputLayout` will grab the hint itself from the `EditText` when it's first initialized - i.e., when your layout is loaded - but after that, you need to set the hint on the `TextInputLayout` directly. – Mike M. Oct 06 '16 at 03:10

0 Answers0