I want to set the hint with java in EditText(which is in TextInputLayout).
Code used for setting hint:
aET = (EditText) findViewById(R.id.aET);
aET.setHint("h?");
But even when edittext is focused, Hint is displayed twice(inside edittext also).
Please let me know if anyone had faced and found some workaround
when editText is focused...
when editText is not focused..
EDIT[10th July 2015]:
<android.support.design.widget.TextInputLayout
android:id="@+id/aTIL"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/aET" />
</android.support.design.widget.TextInputLayout>
Simple use this programmatically it's working for me
You can customize the style as i mention below...
I also had this issue.
when I needed to update the hint, I (erroneously) did that on both the
EditText
and theTextInputLayout
, which resulted in a blur.solution was to not call
EditText.setHint()
but onlyTextInputLayout.setHint()
This problem occurs because the hint from the xml is passed on to the TextInputLayout, so it can be displayed as a floating hint. But when you set it programatically, the hint is set to the EditText, which then results in two hints (one from the xml that is a floating hint and one you set programatically and is a normal EditText hint). If you wish to change the floating hint, you must set the hint on TextInputLayout.
You code will then look like this:
first compile dependency compile 'com.rengwuxian.materialedittext:library:2.1.3'
add this in your xml
add xmlns:app="http://schemas.android.com/apk/res-auto"
You can go by using two hint texts. One for the TextInputLayout and other for the edit text inside it.Below is the reference:
But this has a problem. The UI will look like below. The hints will overlap.
To avoid the above ugly UI, you have to control this from program.Set the hint text of the EditText only when there is focus on the field, else remove the hint text.
Remove the above line from the layout xml file and do as below:
I hope this solves you issue. God Speed !!!
I found the solution !
In your EditText add
And in the code set the hint from the EditText
The hint in your editText is hidden and the hint from the TextInputLayout is shown.
EDIT :
Other solution (The best)
Update Graddle with the new version of android:design