76

I have an EditText and it's parent is TextInputLayout. I am trying to give hint programmatically for EditText, (not in layout) in this case Text input hint animation is not working, it's working like simple EditText. can some one suggest how to handle it.

below is my layout.

<android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/post_EditTextPostAnAd"
        style="@style/abc_EditView" />

</android.support.design.widget.TextInputLayout>
Cœur
  • 37,241
  • 25
  • 195
  • 267
prGD
  • 1,501
  • 2
  • 12
  • 22

1 Answers1

206

You have to set hint to TextInputLayout Here is the code.

TextInputLayout textInputLayout = (TextInputLayout)findViewById(R.id.text_input_layout);
textInputLayout.setHint("Hello");

Updated

In Kotlin:

val textInputLayout = findViewById(R.id.text_input_layout)
textInputLayout.hint = "Hello"
Nitin Patel
  • 1,605
  • 13
  • 31
Sujit
  • 10,512
  • 9
  • 40
  • 45
  • 1
    Glad to know that it working....this is strange but you have to set hint to TextInputLayout programmatically to show in on floating label . – Sujit Dec 10 '15 at 10:11
  • 4
    The code breaks Accessibility support (TalkBack). The only working solution I've come up with ` TextInputLayout textInputLayout = (TextInputLayout)findViewById(R.id.text_input_layout); textInputLayout.setHint("Hello"); textInputLayout.getEditText().setHint(hint); textInputLayout.getEditText().setHintTextColor(getResources().getColor(android.R.color.transparent));` – malinjir Feb 27 '18 at 09:42