TextInputLayout has no effect for giving hint programmatically in EditText

AndroidAndroid Textinputlayout

Android Problem Overview


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>

Android Solutions


Solution 1 - Android

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"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionprGDView Question on Stackoverflow
Solution 1 - AndroidSujitView Answer on Stackoverflow