- How to change the floating hint color of TextInputLayout if EditText inside is disabled
- 6 Answers 6
- Change EditText hint color when using TextInputLayout
- 28 Answers 28
- Programmatically set TextInputLayout Hint Text Color and Floating Label Color
- 8 Answers 8
- Changing the default TextInputLayout Border & Hint Color when focused & not focused #1492
- Comments
- akinfopark commented Jul 20, 2020
- gabrielemariotti commented Jul 20, 2020
- akinfopark commented Jul 21, 2020 •
- gabrielemariotti commented Jul 21, 2020
- Lukman-AMIKOM commented Oct 31, 2020 •
- gabrielemariotti commented Oct 31, 2020
How to change the floating hint color of TextInputLayout if EditText inside is disabled
I am using EditText with TextInputLayout . I just want to change the floating hint color of TextInputLayout if the EditText is disabled. I tried with selector it is not working.
6 Answers 6
There’s one method called setHintTextAppearance(int styleId) in TextInputLayout class. You can use this method to set difference colors to hint text on basis of enabled/disabled state.
And in your styles.xml
If you want to change hint of every TextInputLayout with same color you can change it from style with below code.
here I have used this code for only one TextInputLayout and it has changed its hint color, text color, color of textinputlayout when selected, unselected too.
Using android:theme is important to apply it for lollipop and above.
Do following steps :- 1. Add this style into your styles.xml
2.Use it like bellow
Try app:hintTextAppearance in your android.support.design.widget.TextInputLayout . By defining a style for app:hintTextAppearance , you can also simply set the color of floating label. in styles.xml:
For other EditTextlayout it will pick color from colorAccent defined in your application theme.
Источник
Change EditText hint color when using TextInputLayout
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
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):
28 Answers 28
Define android:textColorHint in your application theme:
Create custom style in style.xml
Then in your layout xml file, add theme attribute as below
hope this works
Add textColorHint property to your edit text
or whichever color you want
got the same problem. Resolved by putting these lines in parent theme.
If you put these
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.
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.
Refer the below code it worked for me.But it will affect all your controls color.
With the Material Components library you can customize the TextInputLayout the hint text color using:
- 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)
In the TextInputLayout that holds the EditText, add:
A lot answers but need only a line for this:
android:textColorHint=»#000000″
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.
2 — Set color when TextInputLayout is floating/focused/tapped.
3 — Set color of the line under TextInputLayout.
4 — Set color of the error under TextInputLayout.
android:textColorHint=»#FFFFFF» sometime works and sometime doesnt. For me below solution works perfectly
Try The Below Code It Works In your XML file and TextLabel theme is defined in style.xml
In Styles Folder TextLabel Code
If you just want to change the color of label in false state then colorAccent , colorControlNormal and colorControlActivated are not required
You can use android:textColorHint=»@color/color_black» inside TextInputlayout It worked for me.
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.
Once I removed this everything worked fine.
try this may this help
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
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
then inside your TextInputLayout you can put it like this
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 .
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:
Then in your styles.xml you would put:
Finally indicate your style in the actual TextInputLayout For some reason you also need to set android:textColorHint for default text color of hint:
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:
And apply this style to the «app:hintTextAppearance» property of the TextInputLayout as below:
Here is the complete customization of the google material text input layout. This maybe helpful for you
The high light color is White:
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.
Источник
Programmatically set TextInputLayout Hint Text Color and Floating Label Color
I use a TextInputLayout, I would want to programmatically set the hint text color and the floating label color if the input field is mandatory. Before moving to TextInputLayout I used to set the hint text color programmatically using the following
Can someone guide me on how to set the hint text color and the floating label color programmatically for a TextInputLayout.
In the screenshot attached i would want the hint text Address 1 to be in red when not focused and the on focus the floating label Address 1 should be in red.
8 Answers 8
I changed focused color with reflection. Here’s the snippet it may help someone.
EDIT 2018-08-01:
If you are using design library v28.0.0 and later, fields had changed from mDefaultTextColor to defaultHintTextColor and from mFocusedTextColor to focusedTextColor .
Check decompiled class for other fields.
In the layout:
in a style:
in the code:
Please, take a good look at the documentation here: TextInputLayout Methods
There is a method :
Which takes a resource id that could be a style resource!
I would try this and see how it goes!
I hope it helps you!
Normally TextInputLayout hint text color comes from app’s colorAccent.
But if you want to change then you can use style for that.
But if you want to add red color then how you can differentiate with error color means basic standard error have Red color.
textField.setHintTextColor(Color.RED); Can someone guide me on how to set the hint text color and the floating label color programmatically for a TextInputLayout.
setHintTextColor works for API 23+
For Changing the both Focused Color and Default Text Color for TextInput Layout
EDIT : To Change AppCompactEditText line color
You need to set the backgroundTintList (or supportBackgroundTintList ) on the EditText to an instance of ColorStateList containing only the color you wish to change the tint to. An easy way to do this in a backwards-compatible way looks like this:
This will give the EditText the desired underline color.
Let me share my experience on this. I also tried all solutions given in every related question to this one. i.e. Change hint color of child widget to TextInputLayout
I am glad to share the answer to this question with a little detail.
All we need to know is:-
Adding below line to style of either TextInputLayout or its child widget, is not much a help.
@color/white
as it will use colorAccent whenever the focus is received/granted to editable widget.
The actual answer to this problem is to add that style line in Application’s style tag, by which it will set hint color when that or any editable area is not in focus. (That is the point we miss everytime).
Please let me know if we have other information on this.
Источник
Changing the default TextInputLayout Border & Hint Color when focused & not focused #1492
Comments
akinfopark commented Jul 20, 2020
The Latest version of material components library by takes the dark grey & colorPrimary value for border color & hint text color when not focused & focused respectively. This can be a problem when we have to use colorPrimary as screen background. How do I change these default colors for these?
The text was updated successfully, but these errors were encountered:
gabrielemariotti commented Jul 20, 2020
You can define a custom style:
or you can simply override them with
akinfopark commented Jul 21, 2020 •
You can define a custom style:
or you can simply override them with
The 1st method is working for hint text but the border changes color only when it is focused else the border background is the default grey. And the cursor color is also colorPrimary how to change that?
gabrielemariotti commented Jul 21, 2020
but the border changes color only when it is focused
You can define the boxStrokeColor attribute as a selector:
Lukman-AMIKOM commented Oct 31, 2020 •
@gabrielemariotti I’m trying to set the hint text color to 3 different colors, e.g. green for when it’s focused & enabled, blue for when it’s unfocused & enabled, and red for when it’s disabled.
How can I accomplish this?
So far, I only managed to set it two colors, one color is applied to when the textInputLayout is in two states: disabled & (unfocused + enabled), the other one is applied when it’s focused and enabled.
gabrielemariotti commented Oct 31, 2020
You can try with:
with the @color/text_color_hint selector:
and the @color/text_input_layout_stroke_color selector:
Источник