setError for TextInputLayout showing Error - android

TextInputLayout working fine, when tried to set Error it showing error.
Code:
if (etFirstName.getText().length() == 0) {
etFirstName.requestFocus();
tvFirstName.setError("Please enter firstname");
} else {
tvFirstName.setError(null);
tvFirstName.setErrorEnabled(false);
}
Check Log:
java.lang.RuntimeException: Failed to resolve attribute at index 24
at android.content.res.TypedArray.getColor(TypedArray.java:401)
at android.widget.TextView.<init>(TextView.java:692)
at android.widget.TextView.<init>(TextView.java:629)
at android.widget.TextView.<init>(TextView.java:625)
at android.widget.TextView.<init>(TextView.java:621)
at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:297)
at android.support.design.widget.TextInputLayout.setError(TextInputLayout.java:344)

Although I did not fully understand why the problem occurs, it must have to do something about how Android applies colors to Views according to its states.
Here is the way I solved the problem:
1) Define custom style, that will be used only for styling the errors (or hints) only:
In your res/values/styles.xml add new style node:
<style name="error" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorAccent</item> <!--apply the color you wat here -->
<item name="android:textSize">12dp</item>
</style>
2) Apply the style to your TextInputLayout:
Also, make sure, that you specify errorEnabled attribute:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_email_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:errorEnabled="true"
app:errorTextAppearance="#style/error"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="#string/hint_email"/>
</android.support.design.widget.TextInputLayout>

Give valid style for your TextInputLayout(
android:theme="#style/Theme.AppCompat")
<android.support.design.widget.TextInputLayout
android:id="#+id/testingInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat">
<EditText
android:id="#+id/testingEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/testText"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
You need to add appCompat & support design dependency (if not)
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
In your manifest file add AppCompat theme,
<application
...
android:theme="#style/Theme.AppCompat">

Sytle theme for textinputlayout :
<style name="HintInputTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">#color/input_floating_color</item>
<item name="android:textSize">22dp</item>
<item name="colorAccent">#color/input_floating_color</item>
</style>
<style name="InputTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">#ff000000</item>
<item name="android:textColorHint">#ff000000</item>
<item name="android:textSize">24dp</item>
<item name="colorAccent">#ff000000</item>
</style>
<style name="ErrorTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">#ffff0000</item>
<item name="android:textColorHint">#ffff0000</item>
<item name="android:textSize">18sp</item>
<item name="colorAccent">#ffff0000</item>
</style>
Use in Layout as :
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:id="#+id/name_signup"
app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorTextAppearance"
app:hintTextAppearance="#style/HintInputTextAppearance"
android:layout_marginLeft="#dimen/left_margin_login"
android:layout_marginRight="#dimen/right_margin_login"
android:layout_height="match_parent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:textAppearance="#style/InputTextAppearance"
android:layout_height="wrap_content"
android:hint="Name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:id="#+id/email_signup"
app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorTextAppearance"
app:hintTextAppearance="#style/HintInputTextAppearance"
android:layout_marginLeft="#dimen/left_margin_login"
android:layout_marginRight="#dimen/right_margin_login"
android:layout_height="match_parent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:textAppearance="#style/InputTextAppearance"
android:layout_height="wrap_content"
android:hint="Email" />
</android.support.design.widget.TextInputLayout>

Solution by #Sevastyan works great for using xml layout.
However, if i have a TextInputLayout and a TextInputEditText which i created programmatically, and i did this:
tilCode.setErrorEnabled(true);
tilCode.setErrorTextAppearance(R.style.error);
I will get an error. But just:
tilCode.setErrorTextAppearance(R.style.error);
Works for me.

Use this it never need Theme.AppCompat
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tv_metadata_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/tv_metadata_Details"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

Use TextUtils
if(TextUtils.isEmpty(etFirstName.getText().toString()))
{
etFirstName.setError("Filed is mandatory!");
view = etFirstName;
}

Try below code to show error in TextInputLayout:
tvFirstName.setErrorEnabled(true);
tvFirstName.setError("Please Enter firstName");

Related

why can't I change hintTextAppearance via android:theme?

Hello all I am new to android themes and styles. According to official documentations
A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a type of style that's applied to an entire app, activity, or view hierarchy—not just an individual view
But i can not change some attributes via android:theme attribute, but i can change via style
Here I have this style file:
<style name="Style.InputLayout" parent="Widget.Design.TextInputLayout">
<item name="errorTextAppearance">#style/ErrorTextAppearance</item>
<item name="hintTextAppearance">#style/HintTextAppearance</item>
<item name="errorEnabled">true</item>
</style>
<style name="HintTextAppearance" parent="TextAppearance.Design.Hint">
<!-- Inactive and Active label color-->
<item name="android:textColor">?attr/colorShadow</item>
</style>
<style name="ErrorTextAppearance" parent="TextAppearance.Design.Error">
<!-- Error text color-->
<item name="android:textColor">?attr/colorError</item>
</style>
And I have a TextInputLayout as:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tfUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Style.InputLayout"
android:hint="Username">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.EditText"/>
</com.google.android.material.textfield.TextInputLayout>
This works as i expected. But when I change style attribute to android:theme in TextInputLayout like below:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tfUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Style.InputLayout"
android:hint="Username">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.EditText"/>
</com.google.android.material.textfield.TextInputLayout>
It does not work. Why is that?
It does not work. Why is that?
<com.google.android.material.textfield.TextInputLayout
android:theme="#style/Style.InputLayout"
It doesn't work because it is wrong.
You can use something like:
<com.google.android.material.textfield.TextInputLayout
android:theme="#style/Style.MyColor"
...>
With:
<style name="MyColor" parent="">
<item name="colorPrimary">#color/.....</item>
</style>
In this way you can modify the theme attributes for that view and any child views, which is useful for overriding theme color palettes in a specific portion of your interface.
You can find more info in the official doc.
Use like this:
Use this code on styles
<style name="MyColor" parent="">
<item name="android:colorControlActivated">#color/colorTextGray</item>
<itemname="android:colorControlHighlight">#color/colorTextGray</item>
<item name="android:colorControlNormal">#color/colorTextGray</item>
</style>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/layoutTextInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:theme="#style/MyColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline131"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline121"
app:layout_constraintTop_toBottomOf="#+id/ed_phone"
app:layout_constraintVertical_bias="0.0"
app:passwordToggleDrawable="#drawable/show_password_selector"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#color/colorWhite">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/ed_password_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:inputType="textPassword"
android:textColor="#color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline131"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline121"
app:layout_constraintTop_toBottomOf="#+id/ed_phone"
app:layout_constraintVertical_bias="0.0" />
</com.google.android.material.textfield.TextInputLayout>

Material Component is not able to change color

please I try to resolve this problem for two days, but unsuccessfull
I have a problem with new material design components
I used style Widget.MaterialComponents.TextInputLayout.OutlinedBox
I try get this result.. (without change theme colors) only xml or code
my actual widget.. :(
my Theme
Theme.MaterialComponents.Light.NoActionBar.Bridge
xml code of component
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/core_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/TextInputLayout"
app:errorEnabled="true"
android:layout_weight="9">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
tools:hint="Trip name"/>
</com.google.android.material.textfield.TextInputLayout>
style
<style name="TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="hintTextAppearance">#style/HintText</item>
</style>
<style name="HintText" parent="TextAppearance.MaterialComponents.Subtitle2">
<item name="android:textColor">?secondaryVariant</item>
</style>
I tried everything from internet, but i dont know where is a problem. thanks for any help
In gradle i have all latest versions of libs and build version
If zou want additional info write.
Thanks for any help
<style name="TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="colorAccent">#color/HintText</item>
</style>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/core_text"
style="#style/TextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:theme="#style/TextInputLayout"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
tools:hint="Trip name" />
</com.google.android.material.textfield.TextInputLayout>
Also if you need to change box stroke, you need to the override default color
<color name="colorTextInputStroke">#CCD1D3</color>
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">
#color/colorTextInputStroke
</color>
this problem can resolve with this lines in custom theme
<item name="colorPrimary">?secondary</item>
<item name="colorPrimaryDark">?secondaryVariant</item>
<item name="colorOnPrimary">?onSecondaryH</item>
<item name="colorSecondary">?primary</item>
<item name="colorOnSecondary">?onPrimaryH</item>

Color hint when selected [duplicate]

I am using the new TextInputLayout from the design library. I am able to get it to show and to change the color of the floating label. Unfortunately the actual EditText hint is now always white.
I have tried changing the hintColor in XML, styles, and programmatically and also tried using the android.support.v7.widget.AppCompatEditText
but the EditText hint always shows white.
Here is my XML for my TextInputLayout and EditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.support.design:hintTextAppearance="#style/GreenTextInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/city"
android:textColorHint="#color/black"
android:hint="#string/city" />
</android.support.design.widget.TextInputLayout>
And here is the style I am using for the TextInputLayout (I tried making the hintTextColor attribute black but didn't do anything for me):
<style name="GreenTextInputLayout" parent="#style/TextAppearance.AppCompat">
<item name="android:textColor">#color/homestory_green</item>
</style>
Define android:textColorHint in your application theme:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorHint">#color/secondary_text</item>
</style>
Source
Or, in your layout, like:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.support.design:hintTextAppearance="#style/GreenTextInputLayout"
android:textColorHint="#color/secondary_text">
Create custom style in style.xml
<style name="EditTextHint" parent="TextAppearance.AppCompat">
<item name="colorAccent">#android:color/white</item>
<item name="android:textColorHint">#color/BackgroundtWhiteColor</item>
<item name="colorControlNormal">#color/BackgroundtWhiteColor</item>
<item name="colorControlActivated">#color/your color</item>
<item name="colorControlHighlight">#color/BackgroundtWhiteColor</item>
</style>
Then in your layout xml file, add theme attribute as below
<android.support.design.widget.TextInputLayout
android:theme="#style/EditTextHint"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
hope this works
Add textColorHint property to your edit text
android:textColorHint="#F6F6F6"
or whichever color you want
got the same problem. Resolved by putting these lines in parent theme.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/ColorPrimaryDark</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<item name="colorAccent">#color/AccentColor</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:textColorHint">#color/BackgroundtWhiteColor</item>
<item name="colorControlNormal">#color/BackgroundtWhiteColor</item>
<item name="colorControlActivated">#ff0000</item>
<item name="colorControlHighlight">#color/BackgroundtWhiteColor</item>
<!-- Customize your theme here. -->
</style>
If you put these
<item name="android:textColorHint">#color/BackgroundtWhiteColor</item>
<item name="colorControlNormal">#color/BackgroundtWhiteColor</item>
<item name="colorControlActivated">#ff0000</item>
<item name="colorControlHighlight">#color/BackgroundtWhiteColor</item>
in a separate style and apply it to TextInputLayout or Edittext it won't appear. You HAVE to place it in application's parent theme.
With the Material Components library you can customize the TextInputLayout the hint text color using:
In the layout:
app:hintTextColor attribute : the color of the label when it is collapsed and the text field is active
android:textColorHint attribute: the color of the label in all other text field states (such as resting and disabled)
Something like:
<com.google.android.material.textfield.TextInputLayout
app:hintTextColor="#color/mycolor"
android:textColorHint="#color/text_input_hint_selector"
.../>
I'm not sure what causes your problem put this code works perfectly for me. I think it has something to do with using the correct xml namespace (xmlns). I'm not sure if using android.support.design without xml namespace attribute is supported. Or it has something to do with the textColorHint attribute you are using on the EditText itself.
Layout:
<android.support.design.widget.TextInputLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:hintTextAppearance="#style/GreenTextInputLayout">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="test"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
Style:
<style name="GreenTextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
Refer the below code it worked for me.But it will affect all your controls color.
<!-- In your style.xml file -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!--EditText hint color-->
<item name="android:textColorHint">#color/default_app_white</item>
<!-- TextInputLayout text color-->
<item name="colorControlActivated">#color/default_app_green</item>
<!-- EditText line color when EditText on-focus-->
<item name="colorControlHighlight">#color/default_app_green</item>
<!-- EditText line color when EditText in un-focus-->
<item name="colorControlNormal">#color/default_app_white</item>
</style>
In the TextInputLayout that holds the EditText, add:
android:textColorHint="someColor"
A lot answers but need only a line for this:
android:textColorHint="#000000"
<EditText
android:id="#+id/edtEmail"
android:textColorHint="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
if you are using the Material design library. Currently, I am using the version
implementation 'com.google.android.material:material:1.3.0-alpha01'
1 - Set color when TextInputLayout is resting.
<item name="android:textColorHint">#color/your_color_hint</item>
2 - Set color when TextInputLayout is floating/focused/tapped.
<item name="hintTextColor">#color/your_color_floating_hint</item>
3 - Set color of the line under TextInputLayout.
<item name="boxStrokeColor">#color/TextViewColor_line</item>
4 - Set color of the error under TextInputLayout.
<item name="boxStrokeErrorColor">#color/colorPrimary</item>
You can use android:textColorHint="#color/color_black" inside TextInputlayout It worked for me.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp_10"
android:textColorHint="#color/color_black"
app:hintTextAppearance="#style/TextLabel">
<EditText
android:id="#+id/et_state"
style="#style/profile_editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/billingState"
android:text="#string/billingState"
/>
</android.support.design.widget.TextInputLayout>
According to this:
https://code.google.com/p/android/issues/detail?id=176559
Try this:
<android.support.design.widget.TextInputLayout
android:textColorHint="#A7B7C2"
android:layout_width="match_parent"
android:layout_height="50dp">
<EditText
android:id="#+id/et_confirm_password"
android:textColor="#android:color/black"
android:hint="Confirm password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>
It works in 23.1.1
Looks like the parent view had a style for a 3rd party library that was causing the EditText to be white.
android:theme="#style/com_mixpanel_android_SurveyActivityTheme"
Once I removed this everything worked fine.
try this may this help
edittext.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onTextChanged", 2000).show();;
//newuser.setTextColor(Color.RED);
edittext.setHintTextColor(Color.RED);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "afterTextChanged", 2000).show();;
}
});
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:textColor="#color/black"
android:textColorHint="#color/grey"/>
</android.support.design.widget.TextInputLayout>
Use textColorHint to set the color that you want as the Hint color for the EditText. The thing is that Hint in the EditText disappears not when you type something, but immediately when the EditText gets focus (with a cool animation). You will notice this clearly when you switch focus away and to the EditText.
late but it may help someone i have done like this
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:textColorHint="#8cffffff">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/email_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/security_email"
android:inputType="textEmailAddress"
android:textColor="#color/white"
app:backgroundTint="#8cffffff" />
</android.support.design.widget.TextInputLayout>
<item name="colorAccent">#android:color/black</item>
change your colorAccent to your desired color inside your Theme,this will change your EditText line,Cursor as well as your hint
or you can also include this style inside your style.xml
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#android:color/black</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#android:color/black</item>
<item name="colorControlNormal">#android:color/black</item>
<item name="colorControlActivated">#android:color/black</item>
</style>
then inside your TextInputLayout you can put it like this
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/password"
android:drawableStart="#drawable/password"
android:maxLines="1"
android:hint="password"
android:inputType="textWebPassword" />
</android.support.design.widget.TextInputLayout>
From the documentation:
The hint should be set on the TextInputLayout, rather than the EditText. If a hint is specified on the child EditText in XML, the TextInputLayout might still work correctly; TextInputLayout will use the EditText's hint as its floating label. However, future calls to modify the hint will not update TextInputLayout's hint. To avoid unintended behavior, call setHint(CharSequence) and getHint() on TextInputLayout, instead of on EditText.
Try setting android:hint and app:hintTextColor on TextInputLayout instead of on TextInputEditText.
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_passdword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#d3d3d3">
<EditText
android:id="#+id/etaddrfess_ciwty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="50dp"
android:fontFamily="#font/frutiger"
android:gravity="start"
android:hint="#string/address_city"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="14sp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</android.support.design.widget.TextInputLayout>``
If you are using new androidx Material design library com.google.android.material
then you can use colorstatelist to control hint text color in focused, hovered and default state as follows. (inspired by this)
In res/color/text_input_box_stroke.xml put something like the following:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#fcc" android:state_focused="true"/>
<item android:color="#cfc" android:state_hovered="true"/>
<item android:color="#ccf"/>
</selector>
Then in your styles.xml you would put:
<style name="MtTILStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
<item name="hintTextColor">#color/text_input_box_stroke</item>
</style>
Finally indicate your style in the actual TextInputLayout
For some reason you also need to set android:textColorHint for default text color of hint:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/my_layout_id"
style="#style/LoginTextInputLayoutStyle"
android:textColorHint="#ccf"
...
Here is the complete customization of the google material text input layout. This maybe helpful for you
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="#dimen/_24sdp"
android:layout_marginTop="#dimen/_24sdp"
android:hint="#string/username"
android:textColorHint="#color/tint"
app:hintEnabled="true"
app:hintAnimationEnabled="false"
app:startIconDrawable="#drawable/ic_user"
app:startIconTint="#color/tint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/guideline"
app:boxCornerRadiusBottomEnd="#dimen/_45sdp"
app:boxCornerRadiusBottomStart="#dimen/_45sdp"
app:boxCornerRadiusTopEnd="#dimen/_45sdp"
app:boxCornerRadiusTopStart="#dimen/_45sdp"
app:boxStrokeColor="#color/red"
app:boxStrokeWidth="#dimen/_1sdp"
<!-- for password
app:passwordToggleEnabled="true"
app:passwordToggleTint="#color/tint" -->
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="#dimen/_40sdp"
android:padding="0dp"
android:fontFamily="#font/poppins_medium"
android:textColor="#color/black"
android:inputType="textEmailAddress"/>
</com.google.android.material.textfield.TextInputLayout>
This Should 100% work
android:textColorHint="#color/white"
You must set hint color on TextInputLayout.
When I tried to set theme attribute to TextInputLayout, the theme was also getting applied to its child view edittext, which I didn't wanted.
So the solution which worked for me was to add a custom style to the "app:hintTextAppearance" property of the TextInputLayout.
In styles.xml add the following style:
<style name="TextInputLayoutTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">#color/text_color</item>
<item name="android:textSize">#dimen/text_size_12</item>
</style>
And apply this style to the "app:hintTextAppearance" property of the TextInputLayout as below:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/mobile_num_til"
android:layout_width="0dp"
android:layout_height="#dimen/dim_56"
app:layout_constraintStart_toStartOf="#id/title_tv"
app:layout_constraintEnd_toEndOf="#id/title_tv"
app:layout_constraintTop_toBottomOf="#id/sub_title_tv"
android:layout_marginTop="#dimen/dim_30"
android:padding="#dimen/dim_8"
app:hintTextAppearance="#style/TextInputLayoutTextAppearance"
android:background="#drawable/rect_round_corner_grey_outline">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/mobile_num_et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/mobile_number"
android:gravity="center_vertical"
android:background="#android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
Try code below:
The high light color is White:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextStyle"
>
<EditText
android:id="#+id/input_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:drawablePadding="14dp"
android:drawableLeft="8dp"
android:textColor="#color/white"
android:hint="Mobile" />
</android.support.design.widget.TextInputLayout>
style: TextStyle
<style name="TextStyle" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/white</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/white</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
</style>
Here is my experience with this similar issue & the required solution.
Requirement:
Need to create customize TextInputEditText (can say some should be transparent and some should be not but use custom colors for various events)
Problem faced:
android:textColorHint is not working as required.
Solutions tried, which failed:
Used android:textColorHint in style and applied to TextInputEditText. No results or difference.
Set android:textColorHint in application's theme applied. It do helped but it was now set for entire application. (Not up-to mark to requirement)
After a lot of RnD, the best SOLUTION found was in an article which described that we need to apply theme to TextInputLayout or to it's parent view rather then only applying style to TextInputEditText or to it's parent view.
Please check TextInputLayout proper Theming which told that how we are at wrong track.
I only wanted to change the label color when it is lifted to top. But setting textColorHint changes the color at every state. So, this worked for me:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="colorControlActivated">#color/colorPrimary</item>
...
</style>
This will change the color when the input is focused.
Use TextInputLayout.setDefaultHintTextColor

How to fix missing styles when using theme in TextInputLayout

I use the TextInputLayout widget for custom EditText.
<android.support.design.widget.TextInputLayout
android:theme="#style/EditTextHint"
android:id="#+id/panelID"
android:paddingTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/txtID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Engage code here"
android:inputType="textCapWords"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:maxLines="1"
tools:ignore="HardcodedText" />
</android.support.design.widget.TextInputLayout>
With style :
<style name="EditTextHint" parent="TextAppearance.AppCompat">
<item name="colorAccent">#DD4B39</item>
<item name="android:textColorHint">#DD4B39</item>
<item name="colorControlNormal">#545454</item>
<item name="colorControlActivated">#545454</item>
<item name="colorControlHighlight">#545454</item>
</style>
To get some custom EditText. But I found some error
When I ignore the error, and still run my application there is no error, just a warning on the design panel in android studio
What should I add in the style that the error could be disappear?
Thanks
your parent should be #android:style/TextAppearance instead of TextAppearance.AppCompat
You can try to use another nameSpace for attribute colorControlHighlight
Try this:
xmlns:app="http://schemas.android.com/apk/res-auto"
instead this
xmlns:android="http://schemas.android.com/apk/res/android"

How to change the hint size of TextInputLayout

This is my xml
<android.support.design.widget.TextInputLayout
style="#style/main_input_text"
android:layout_marginTop="#dimen/activity_medium_margin"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout">
<android.support.v7.widget.AppCompatEditText
style="#style/main_edit_text"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
And this is style
<style name="main_input_text">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">#dimen/activity_edittext_height</item>
<item name="android:background">#drawable/mc_shape_border_button_transparent</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingTop">#dimen/activity_extra_small_margin</item>
<item name="android:paddingBottom">#dimen/activity_extra_small_margin</item>
<item name="android:keyTextSize">8sp</item>
<item name="android:textSize">8sp</item>
</style>
I don't find something like hintSize, textSize and keyTextSize not helping
In your styles.xml
<style name="TextLabel" parent="TextAppearance.Design.Hint">
<item name="android:textSize">16sp</item>
</style>
And then in your layout file:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="12dp"
app:hintTextAppearance="#style/TextLabel"
android:minHeight="30dp">
Change the TextInputLayout's app:errorTextAppearance in XML.
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:errorTextAppearance="#style/CustomTextInputLayoutStyle.ErrorTextStyle">
Where CustomTextInputLayoutStyle.ErrorTextStyle is defined in styles.xml as
<style name="CustomTextInputLayoutStyle.ErrorTextStyle" parent="TextAppearance.Design.Error">
<item name="android:textSize">10sp</item>
</style>
#Santiago Martínez answer only works for hints on non empty Edittext (inside TextInputLayout)
But for empty Edittext, TextInputLayout hint takes property from Edittext textSize.
1) Add hintTextAppearance to your InputLayout with a style
<android.support.design.widget.TextInputLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextInputLayoutHintText" >
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
2) Then just add the style to your styles.xml
<style name="TextInputLayoutHintText">
<item name="android:textColor">#color/gray</item>
<item name="android:textSize">12sp</item></style>
For material 1.4.0
implementation 'com.google.android.material:material:1.4.0'
You only need to change the android:textSize attribute for the TextInputEditText for the hint size to change.
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"/>
</com.google.android.material.textfield.TextInputLayout>
You can reduce the font size on the EditText - that will reduce the size of the hint as well. i.e. android:textSize="16sp"

Categories

Resources