TextInputLayout has no effect for giving hint programmatically in EditText

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 18:17:02

问题


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>

回答1:


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"


来源:https://stackoverflow.com/questions/34198599/textinputlayout-has-no-effect-for-giving-hint-programmatically-in-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!