TextInputLayout and EditText double hint issue
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:
aTIL = (TextInputLayout) findViewById(R.id.aTIL);
aTIL.setHint("h?");
You can go by using two hint texts. One for the TextInputLayout and other for the edit text inside it.Below is the reference:
<android.support.design.widget.TextInputLayout
style="@style/editText_layout"
android:id="@+id/entryScreenProduction_editText_percentCompleted_layout"
android:hint="%Completed">
<EditText
android:id="@+id/entryScreenProduction_editText_percentCompleted"
style="@style/editTextNotes"
android:gravity="center_vertical|top"
android:inputType="numberDecimal"
android:textAlignment="viewStart"
android:hint="0.0"/>
</android.support.design.widget.TextInputLayout>
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.
android:hint="0.0"
Remove the above line from the layout xml file and do as below:
m_editText_completed = (EditText) findViewById(R.id.entryScreenProduction_editText_percentCompleted);
m_editText_completed.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if(b){
m_editText_completed.setHint("0.0");
}
else {
m_editText_completed.setHint("");
}
}
});
I hope this solves you issue. God Speed !!!
I also had this issue.
when I needed to update the hint, I (erroneously) did that on both the EditText
and the TextInputLayout
, which resulted in a blur.
solution was to not call EditText.setHint()
but only TextInputLayout.setHint()
I found the solution !
In your EditText add
android:textColorHint="@android:color/transparent"
And in the code set the hint from the EditText
aET.setHint("h?");
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
compile 'com.android.support:design:22.2.1'