I need to custom create a TextInputLayout where the EditText can have padding but the upper hint and lower error text does not share that padding like this in Android.
When I'm adding padding to the EditText inside TextInputLayout, the hint and error text also showing that padding like this.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/et_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorText="Invalid Number" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="#dimen/dp_54"
android:paddingEnd="0dp"
android:paddingBottom="#dimen/dp_20"
android:inputType="phone"
style="#style/editTextStyle_large"
android:hint="#string/w12_mobile_sign_in_hint"/>
</com.google.android.material.textfield.TextInputLayout>
I'm creating a login form with TextInputLayout and TextInputEditText but toggle password icon always show in white no matter which color I assign to it as endIconTint. I have tested this on
Android 6
Android 10
both show the same results.
Here is my Form when I use Widget.MaterialComponents.TextInputLayout.OutlinedBox as a style in TextInputLayout. It seems like its not showing drawable but that's not the case its not visible as drawable & input field background color is white. When I click on the end it toggle password.
Here is the form when I use Widget.MaterialComponents.TextInputLayout.FilledBox
And here is my code you can see I'm currently assigning black color to the endIconTint
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/password_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:hint="Password"
app:counterEnabled="true"
app:counterMaxLength="20"
app:endIconMode="password_toggle"
app:endIconTint="#color/black"
app:helperText="required*"
app:helperTextTextColor="#android:color/holo_red_dark"
app:layout_constraintTop_toBottomOf="#id/username_til"
app:passwordToggleEnabled="true"
app:startIconDrawable="#drawable/ic_key">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/password_tiet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLength="20" />
</com.google.android.material.textfield.TextInputLayout>
I cross verified color from the color.xml file and tried other colors too but icon always appear as white. Please let me know what is wrong here or is it a bug?
Thanks & Regards
You have already specify app:endIconMode="password_toggle" so you don't require to set passwordToggleEnabled anymore.
Remove this from TextInputLayout and it resolve your issue.
app:passwordToggleEnabled="true"
I need to animation like this of first:
(Gif from Internet) But even with app:hintAnimationEnabled="true" the animation doesn't work. Always the second example of gif. What could be the problem? What am I doing wrong?
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Login"
app:hintEnabled="true"
app:hintAnimationEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
You need to set the hint for TextInputLayout as well for animations to work, I've only tried setting hint dynamically which works as expected, try setting the hint in xml first to see if it works, if it does not then do it dynamically:
TextInputLayout inputLayout = findViewById(R.id.textInputLayout);
inoutLayout.setHint("Hint");
I want to give padding to hint of edittext in TextInputLayout
where email address is hint and Sample is text
also tried this solution but didn't work.
facing this issue after changing support design library 23.1.0
here is my code
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edtEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_round_edt_grey"
android:focusableInTouchMode="true"
android:hint="#string/emailadd"
android:padding="10dp"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
As per this answer ,if you have custom background set on EditText the android:padding attribute simple doesn't work to alter the spacing b/w the hint text and edit text .So if you have set custom background to your AppCompatEditText, you can use android:translationY attribute in the AppCompatEditText
Please add below line in your AppCompatEditText.
android:translationY="10dp"
hope you got your answer :)
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>
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?");
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'
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()
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 !!!
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"
Simple use this programmatically it's working for me
TextInputLayout til = new TextInputLayout(this);
til.setHintTextAppearance(android.R.style.TextAppearance_Large);
You can customize the style as i mention below...
<style name="TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorPrimaryDark</item>
<item name="android:textColorHint">#color/colorPrimaryDark</item>
<item name="android:textSize">23sp</item>
</style>
TextInputLayout til = new TextInputLayout(this);
til.setHint("hai);
til.setHintTextAppearance(R.style.TextInputLayout);
In my case, I follow this line of code in kotlin
kotlin code
val edPasswordSignIn = findViewById<TextInputEditText>(R.id.edPasswordSignIn)
edPasswordSignIn.setHint("Password")
edPasswordSignIn.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus){
edPasswordSignIn.setHint("Password")
}
else
edPasswordSignIn.setHint("")
}
XML code
<!--TextInput layout which acts as a wrapper to the edit text-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#f29358"
app:hintTextAppearance="#style/TextAppearance.AppCompat.Large"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#color/colorPrimary"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
android:scrollbarSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:gravity="fill_vertical"
app:layout_constraintTop_toTopOf="parent">
<!--Using the TextInputEditText,which is
same as the edit text,but remember-->
<!--that we need to use TextInputEditText
with TextInputLayout-->
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edPasswordSignIn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:backgroundTint="#color/white"
android:gravity="center|left"
android:inputType="textPassword"
android:paddingTop="-2dp"
android:paddingBottom="-1dp"
android:textSize="#dimen/_11sdp" />
</com.google.android.material.textfield.TextInputLayout>
before enter the text
After the enter the text
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
app:hintEnabled="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textField"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Hint" />
</com.google.android.material.textfield.TextInputLayout>
app:hintEnabled="false"
This is enough to hide the default label.