Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout has no effect for giving hint programmatically in EditText

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> 
like image 302
prGD Avatar asked Dec 10 '15 09:12

prGD


People also ask

How do I get TextInputLayout from text?

TextInputLayout textInputCustomEndIcon = findViewById(R. id. editText); final TextInputEditText editText = new TextInputEditText(textInputCustomEndIcon. getContext()); textInputCustomEndIcon.

What is the use of TextInputLayout in Android?

The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.

What is a TextInputLayout?

What is TextInputLayout? TextInputLayout is a view container that is used to add more features to an EditText. It acts as a wrapper for EditText and has some features like: Floating hint. Animation that can be disabled or enabled.


1 Answers

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" 
like image 179
Sujit Avatar answered Oct 09 '22 16:10

Sujit