Skip to content Skip to sidebar Skip to footer

Textinputlayout And Edittext Double Hint Issue

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 e

Solution 1:

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?");

Solution 2:

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'

Solution 3:

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()

Solution 4:

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. enter image description here

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(newView.OnFocusChangeListener() {
            @OverridepublicvoidonFocusChange(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 !!!

Solution 5:

first compile dependency compile 'com.rengwuxian.materialedittext:library:2.1.3'

add this in your xml

<com.rengwuxian.materialedittext.MaterialEditText    
android:id="@+id/etId"android:layout_width="match_parent"android:layout_height="70dip"android:hint="Hint goes here"android:textColor = "#000000"android:textSize="15sp"app:met_accentTypeface="fonts/yourcustomfonts.ttf"app:met_floatingLabel="normal"app:met_floatingLabelTextColor="#ff0000"app:met_floatingLabelTextSize="15sp"app:met_hideUnderline="true"app:met_textColorHint="#ff00ff"app:met_typeface="fonts/yourcustomfont.ttf"/>

add xmlns:app="http://schemas.android.com/apk/res-auto"

Post a Comment for "Textinputlayout And Edittext Double Hint Issue"