I want to set the hint with java in EditText(which is in TextInputLayout).
Code used for setting hint:
aET = (EditText) findViewById(R.id.
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?");
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"
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()
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/password">
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);