I was working on a design that requires all views has an alignment to left.
I'm using TextInputLayout && TextInputEditText there was spaces for hint & text that are solved by setting padding to 0dp for TextInputEditText but, I'm stuck in removing padding/margin start for the bottom line of TextInputEditText.
so, can anyone help me with that simple issues, please?
actual, what I need to do is remove the space at the start of TextInputEditText so bottom line be aligned to left like E
this is my XML
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/_5sdp"
android:paddingBottom="#dimen/_5sdp"
app:endIconDrawable="#mipmap/clear_email"
app:endIconMode="clear_text"
app:endIconTint="#color/grey"
app:errorEnabled="true"
app:hintEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/test"
style="#style/TILStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/opensans_regular"
android:hint="#string/enter_email_address"
android:importantForAutofill="no"
android:inputType="textEmailAddress"
android:theme="#style/Theme.App.Base"
app:hintTextAppearance="#style/TextLabel" />
</com.google.android.material.textfield.TextInputLayout>
for the styles used:
TILStyle
<style name="TILStyle">
<item name="android:lines">1</item>
<item name="android:singleLine">true</item>
<item name="android:gravity">start</item>
<item name="android:textAlignment">viewStart</item>
<item name="android:paddingEnd">0dp</item>
<item name="android:paddingStart">0dp</item>
<item name="android:paddingBottom">#dimen/_12sdp</item>
</style>
Theme.App.Base
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/grey_line</item>
<item name="colorControlActivated">#color/grey_line</item>
<item name="colorControlHighlight">#color/grey_line</item>
</style>
TextLabel
<style name="TextLabel" parent="TextAppearance.Design.Hint">
<item name="android:textSize">16sp</item>
<item name="android:paddingBottom">#dimen/_18sdp</item>
</style>
after long of search and debugging, I found that the issue in these two lines
<item name="android:paddingEnd">0dp</item>
<item name="android:paddingStart">0dp</item>
after deleting them it's solved.
it looks like that there is a default value for it, but I don't know how much are they but, that solved my issue.
if anyone knows the default values please leave a comment.
Related
I am using android design library's TextinputLayout. But couldn't customize the hint color, label color and the underline color of EditText inside TextinputLayout. Please help.
Change bottom line color:
From this answer
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
Change hint color when it is floating
<style name="MyHintStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/main_color</item>
</style>
and use it like this:
<android.support.design.widget.TextInputLayout
...
app:hintTextAppearance="#style/MyHintStyle">
Change hint color when it is not a floating label:
<android.support.design.widget.TextInputLayout
...
app:hintTextAppearance="#style/MyHintStyle"
android:textColorHint="#c1c2c4">
Thanks to #AlbAtNf
With the Material Components Library you can use the com.google.android.material.textfield.TextInputLayout.
You can apply a custom style to change the colors.
To change the hint color you have to use these attributes:
hintTextColor and android:textColorHint.
<style name="Custom_textinputlayout_filledbox" parent="#style/Widget.MaterialComponents.TextInputLayout.FilledBox">
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">?attr/colorPrimary</item>
<!-- The color of the label in all other text field states (such as resting and disabled) -->
<item name="android:textColorHint">#color/selector_hint_text_color</item>
</style>
You should use a selector for the android:textColorHint. Something like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.38" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.6" android:color="?attr/colorOnSurface"/>
</selector>
To change the bottom line color you have to use the attribute: boxStrokeColor.
<style name="Custom_textinputlayout_filledbox" parent="#style/Widget.MaterialComponents.TextInputLayout.FilledBox">
....
<item name="boxStrokeColor">#color/selector_stroke_color</item>
</style>
Also in this case you should use a selector. Something like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_focused="true"/>
<item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>
You can also apply these attributes in your layout:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
app:boxStrokeColor="#color/selector_stroke_color"
app:hintTextColor="?attr/colorPrimary"
android:textColorHint="#color/selector_hint_text_color"
...>
Based on Fedor Kazakov and others answers, I created a default config.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="Widget.Design.TextInputLayout" parent="AppTheme">
<item name="hintTextAppearance">#style/AppTheme.TextFloatLabelAppearance</item>
<item name="errorTextAppearance">#style/AppTheme.TextErrorAppearance</item>
<item name="counterTextAppearance">#style/TextAppearance.Design.Counter</item>
<item name="counterOverflowTextAppearance">#style/TextAppearance.Design.Counter.Overflow</item>
</style>
<style name="AppTheme.TextFloatLabelAppearance" parent="TextAppearance.Design.Hint">
<!-- Floating label appearance here -->
<item name="android:textColor">#color/colorAccent</item>
<item name="android:textSize">20sp</item>
</style>
<style name="AppTheme.TextErrorAppearance" parent="TextAppearance.Design.Error">
<!-- Error message appearance here -->
<item name="android:textColor">#ff0000</item>
<item name="android:textSize">20sp</item>
</style>
</resources>
activity_layout.xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Text hint here"
android:text="5,2" />
</android.support.design.widget.TextInputLayout>
Focused:
Without focus:
Error message:
Add this attribute in Edittext tag and enjoy:
android:backgroundTint="#color/colorWhite"
This Blog Post describes various styling aspects of EditText and AutoCompleteTextView wrapped by TextInputLayout.
For EditText and AppCompat lib 22.1.0+ you can set theme attribute with some theme related settings:
<style name="StyledTilEditTextTheme">
<item name="android:imeOptions">actionNext</item>
<item name="android:singleLine">true</item>
<item name="colorControlNormal">#color/greyLight</item>
<item name="colorControlActivated">#color/blue</item>
<item name="android:textColorPrimary">#color/blue</item>
<item name="android:textSize">#dimen/styledtil_edit_text_size</item>
</style>
<style name="StyledTilEditText">
<item name="android:theme">#style/StyledTilEditTextTheme</item>
<item name="android:paddingTop">4dp</item>
</style>
and apply them on EditText:
<EditText
android:id="#+id/etEditText"
style="#style/StyledTilEditText"
For AutoCompleteTextView things are more complicated because wrapping it in TextInputLayout and applying this theme breaks floating label behaviour.
You need to fix this in code:
private void setStyleForTextForAutoComplete(int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(autoCompleteTextView.getBackground());
DrawableCompat.setTint(wrappedDrawable, color);
autoCompleteTextView.setBackgroundDrawable(wrappedDrawable);
}
and in Activity.onCreate:
setStyleForTextForAutoComplete(getResources().getColor(R.color.greyLight));
autoCompleteTextView.setOnFocusChangeListener((v, hasFocus) -> {
if(hasFocus) {
setStyleForTextForAutoComplete(getResources().getColor(R.color.blue));
} else {
if(autoCompleteTextView.getText().length() == 0) {
setStyleForTextForAutoComplete(getResources().getColor(R.color.greyLight));
}
}
});
If you want to change the bar/line color and the hint text color of the TextInputLayout (what the accent color normally is), then just create this style:
<style name="MyStyle">
<item name="colorAccent">#color/your_color</item>
</style>
Then apply it to your TextInputLayout as a theme:
<android.support.design.widget.TextInputLayout
...
app:theme="#style/MyStyle" />
This basically sets a theme (not style) to one view (as opposed to the whole activity).
A TextinputLayout is not a view, but a Layout, as very nicely described by Dimitrios Tsigouris in his blog post here. Therefore, you don't need a Style, which is for Views only, but use a Theme. Following the blog post, I ended up with the following solution:
Start in your styles.xml with
<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">
<!-- reference our hint & error styles -->
<item name="android:textColor">#color/your_colour_here</item>
<item name="android:textColorHint">#color/your_colour_here</item>
<item name="colorControlNormal">#color/your_colour_here</item>
<item name="colorControlActivated">#color/your_colour_here</item>
<item name="colorControlHighlight">#color/your_colour_here</item>
</style>
And in your layout add
<com.google.android.material.textfield.TextInputLayout
android:theme="#style/TextInputLayoutAppearance"
...
<style name="Widget.Design.TextInputLayout" parent="android:Widget">
<item name="hintTextAppearance">#style/TextAppearance.Design.Hint</item>
<item name="errorTextAppearance">#style/TextAppearance.Design.Error</item>
</style>
You can override this style for layout
And also you can change inner EditText-item style too.
<style name="EditScreenTextInputLayoutStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#color/actionBar_background</item>
<item name="colorControlActivated">#color/actionBar_background</item>
<item name="colorControlHighlight">#color/actionBar_background</item>
<item name="colorAccent">#color/actionBar_background</item>
<item name="android:textColorHint">#color/actionBar_background</item>
</style>
apply this style to TextInputLayout
I used all of the above answers and none worked. This answer works for API 21+. Use app:hintTextColor attribute when text field is focused and app:textColorHint attribute when in other states. To change the bottmline color use this attribute app:boxStrokeColor as demonstrated below:
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeColor="#color/colorAccent"
app:hintTextColor="#color/colorAccent"
android:textColorHint="#android:color/darker_gray"
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
It works for AutoCompleteTextView as well. Hope it works for you:)
Works for me. If you trying EditText with Label and trying change to underline color use this. Change to TextInputEditText instead EditText.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/editTextTextPersonName3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_16sdp"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginRight="#dimen/_8sdp"
android:textColorHint="#color/white"
app:layout_constraintEnd_toStartOf="#+id/guideline3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#color/white"
android:hint="Lastname"
android:textSize="#dimen/_14sdp"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#color/white" />
</com.google.android.material.textfield.TextInputLayout>
Change line color of TextInputLayout + TextInputEditText
colors.xml
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#color/lineColor</color>
styles.xml
<style name="TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="boxStrokeColor">#color/lineColor</item>
<item name="android:textColorHint">#color/hintColor</item>
<item name="boxStrokeWidth">1dp</item>
<item name="boxBackgroundColor">#color/backgroundColor</item>
</style>
<style name="TextInputEditText" parent="ThemeOverlay.MaterialComponents.TextInputEditText.FilledBox.Dense">
<item name="android:textColor">#color/black</item>
</style>
layout.xml
<com.google.android.material.textfield.TextInputLayout
style="#style/TextInputLayout"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputEditText
style="#style/TextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
You can change the label color of TextInputLayout by using app:hintTextAppearance attribute in TextInputLayout.
<android.support.design.widget.TextInputLayout
android:id="#+id/inputlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextAppearance.App.TextInputLayout">
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="#string/email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:paddingStart="5dp"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
Style:
<style name="TextAppearance.App.TextInputLayout"
parent="#android:style/TextAppearance">
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">20sp</item>
</style>
To change edittext underline color, you can use android:backgroundTint
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
android:backgroundTint="#android:color/holo_red_light" />
Create style as mentioned below
<style name="text_input_layout_style">
<item name="colorControlNormal">#color/primary</item>
<item name="colorControlActivated">#color/primary</item>
<item name="colorControlHighlight">#color/primary</item>
</style>
and apply it to your TextInputLayout as android:theme="#style/text_input_layout_style"
And definitely will work for you all.
I needed to change the bottom line color of a TextInputEditText inside a TextInputLayout and then the other answers didn't work out. I finally solved it by setting the colorOnSurface for the TextInputLayouts theme. I'll leave my code here in case it helps someone else.
XML:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme=""#style/TextInputLayoutStyle"">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.te`tfield.TextInputLayout>
Style:
<style name="TextInputLayoutStyle">
<item name="colorOnSurface">#0ff</item>
</style>
XML
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/activity_profile_textInputLayout_mobile"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:hint="Mobile Number"
app:theme="#style/EditBoxColor">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/activity_profile_textInputEditText_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="10"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
Style
<style name="EditBoxColor" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="colorPrimary">#color/colorPurple</item>
<item name="colorPrimaryDark">#color/colorPurple3</item>
</style>
I have a specific implementation of error handling in edit texts. Is there any way i could achieve something like shown below.
I managed to achieve almost similar result. Only part remaining is the validator.
Any help would be appretiated
Edit 1: Attaching code for to help.
<android.support.design.widget.TextInputLayout
style="#style/FrameTextLayout"
android:layout_width="match_parent"
app:theme="#style/GreyHighlight">
<android.support.design.widget.TextInputEditText
android:id="#+id/fragment_sign_up_one.text_email"
style="#style/FrameEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
Values in values\styles.xml
<style name="GreyHighlight" parent="AppThemeNoAction">
<item name="colorControlNormal">#color/colorHeather</item>
<item name="colorControlActivated">#color/colorHeather</item>
<item name="textColorError">#color/colorHeather</item>
</style>
<style name="FrameTextLayout">
<item name="android:background">#drawable/border_background</item>
<item name="android:paddingTop">8dp</item>
<item name="android:layout_height">53dp</item>
<item name="android:layout_marginTop">16dp</item>
</style>
<style name="FrameEditText">
<item name="android:background">#android:color/transparent</item>
<item name="android:maxLines">1</item>
<item name="android:textSize">16.7sp</item>
<item name="android:textColor">#color/colorDarkIndigo</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">8dp</item>
</style>
Also on the sidenote how do we centre hint inside a TextInputLayout. Example attached.
Currently,
Edit 2: Managed to center hint by disabling hint when not in focus by using app:hintEnabled="false" on TextInputLayout.
So i ended up creating a custom view that fulfilled what i needed.
If anyone is interested I created a library for it.
CustomFormViews
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.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:textColor="#color/darkGray" />
<item android:state_pressed="false" android:state_focused="false" android:textColor="#color/lightGray"/>
</selector>
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.
Example :
//for disabled editText
mEditText.setEnabled(false);
mTextInoutLayout.setHintTextAppearance(R.style.CustomHintDisabled);
//for enablededitText
mEditText.setEnabled(true);
mTextInoutLayout.setHintTextAppearance(R.style.CustomHintEnabled);
And in your styles.xml
<style name="CustomHintDisabled" parent="YourBaseTheme.TextAppearance">
<item name="textColor">#color/gray</item>
</style>
<style name="CustomHintEnabled" parent="YourBaseTheme.TextAppearance">
<item name="textColor">#color/black</item>
</style>
If you want to change hint of every TextInputLayout with same color you can change it from style with below code.
<style name="income" parent="TextAppearance.AppCompat">
<item name="android:textColor">#color/green</item>
<item name="android:textColorHint">#color/green</item>
<item name="colorAccent">#color/green</item>
<item name="colorControlNormal">#color/green</item>
<item name="colorControlActivated">#color/green</item>
<item name="colorControlHighlight">#color/green</item>
<item name="android:textColorHighlight">#color/green</item>
</style>
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.
<android.support.design.widget.TextInputLayout
android:id="#+id/input_income"
style="#style/income"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/input_days"
android:layout_margin="10dp"
android:hint="Enter Monthly Take Home Income"
android:textColorHint="#18c418"
android:theme="#style/income"
app:hintAnimationEnabled="true">
</android.support.design.widget.TextInputLayout>
Using android:theme is important to apply it for lollipop and above.
Do following steps :- 1. Add this style into your styles.xml
<style name="FloatingLabel" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/theme</item>
<item name="android:textSize">12sp</item>
</style>
2.Use it like bellow
<android.support.design.widget.TextInputLayout
android:id="#+id/loginPassLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_toRightOf="#+id/user"
android:textColorHint="#color/white"
foo:hintTextAppearance="#style/FloatingLabel">
<com.app.Widget.EditTextPlus
android:id="#+id/edt_email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:hint="Email"
android:inputType="textEmailAddress"
android:maxLength="30"
android:maxLines="1"
android:paddingLeft="10dp"
android:text=""
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="15sp"/>
</android.support.design.widget.TextInputLayout>
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:
<style name="CustomTextAppearance" parent="#android:style/TextAppearance">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/colorAccent</item>
and in your TextInputLayout:
<android.support.design.widget.TextInputLayout
android:id="#+id/lyt_goal"
style="#style/CustomTextInput"
app:hintTextAppearance="#style/CustomTextAppearance">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edt_goal"
style="#style/CustomEditText"
android:hint="#string/str_goal" />
Hope this will help you.
You can set the theme in your TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="First Name"
/>
</android.support.design.widget.TextInputLayout>
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/colorHint</item>
<item name="android:textSize">16sp</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#color/colorNormal</item>
<item name="colorControlActivated">#color/colorActivated</item>
</style>
For other EditTextlayout it will pick color from colorAccent defined in your application theme.
<item name="colorAccent">#color/colorAccent</item>
Hope it will help you.
You have to 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>
Hope this works for you.
I am using android design library's TextinputLayout. But couldn't customize the hint color, label color and the underline color of EditText inside TextinputLayout. Please help.
Change bottom line color:
From this answer
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
Change hint color when it is floating
<style name="MyHintStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/main_color</item>
</style>
and use it like this:
<android.support.design.widget.TextInputLayout
...
app:hintTextAppearance="#style/MyHintStyle">
Change hint color when it is not a floating label:
<android.support.design.widget.TextInputLayout
...
app:hintTextAppearance="#style/MyHintStyle"
android:textColorHint="#c1c2c4">
Thanks to #AlbAtNf
With the Material Components Library you can use the com.google.android.material.textfield.TextInputLayout.
You can apply a custom style to change the colors.
To change the hint color you have to use these attributes:
hintTextColor and android:textColorHint.
<style name="Custom_textinputlayout_filledbox" parent="#style/Widget.MaterialComponents.TextInputLayout.FilledBox">
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">?attr/colorPrimary</item>
<!-- The color of the label in all other text field states (such as resting and disabled) -->
<item name="android:textColorHint">#color/selector_hint_text_color</item>
</style>
You should use a selector for the android:textColorHint. Something like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.38" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.6" android:color="?attr/colorOnSurface"/>
</selector>
To change the bottom line color you have to use the attribute: boxStrokeColor.
<style name="Custom_textinputlayout_filledbox" parent="#style/Widget.MaterialComponents.TextInputLayout.FilledBox">
....
<item name="boxStrokeColor">#color/selector_stroke_color</item>
</style>
Also in this case you should use a selector. Something like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_focused="true"/>
<item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>
You can also apply these attributes in your layout:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
app:boxStrokeColor="#color/selector_stroke_color"
app:hintTextColor="?attr/colorPrimary"
android:textColorHint="#color/selector_hint_text_color"
...>
Based on Fedor Kazakov and others answers, I created a default config.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="Widget.Design.TextInputLayout" parent="AppTheme">
<item name="hintTextAppearance">#style/AppTheme.TextFloatLabelAppearance</item>
<item name="errorTextAppearance">#style/AppTheme.TextErrorAppearance</item>
<item name="counterTextAppearance">#style/TextAppearance.Design.Counter</item>
<item name="counterOverflowTextAppearance">#style/TextAppearance.Design.Counter.Overflow</item>
</style>
<style name="AppTheme.TextFloatLabelAppearance" parent="TextAppearance.Design.Hint">
<!-- Floating label appearance here -->
<item name="android:textColor">#color/colorAccent</item>
<item name="android:textSize">20sp</item>
</style>
<style name="AppTheme.TextErrorAppearance" parent="TextAppearance.Design.Error">
<!-- Error message appearance here -->
<item name="android:textColor">#ff0000</item>
<item name="android:textSize">20sp</item>
</style>
</resources>
activity_layout.xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Text hint here"
android:text="5,2" />
</android.support.design.widget.TextInputLayout>
Focused:
Without focus:
Error message:
Add this attribute in Edittext tag and enjoy:
android:backgroundTint="#color/colorWhite"
This Blog Post describes various styling aspects of EditText and AutoCompleteTextView wrapped by TextInputLayout.
For EditText and AppCompat lib 22.1.0+ you can set theme attribute with some theme related settings:
<style name="StyledTilEditTextTheme">
<item name="android:imeOptions">actionNext</item>
<item name="android:singleLine">true</item>
<item name="colorControlNormal">#color/greyLight</item>
<item name="colorControlActivated">#color/blue</item>
<item name="android:textColorPrimary">#color/blue</item>
<item name="android:textSize">#dimen/styledtil_edit_text_size</item>
</style>
<style name="StyledTilEditText">
<item name="android:theme">#style/StyledTilEditTextTheme</item>
<item name="android:paddingTop">4dp</item>
</style>
and apply them on EditText:
<EditText
android:id="#+id/etEditText"
style="#style/StyledTilEditText"
For AutoCompleteTextView things are more complicated because wrapping it in TextInputLayout and applying this theme breaks floating label behaviour.
You need to fix this in code:
private void setStyleForTextForAutoComplete(int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(autoCompleteTextView.getBackground());
DrawableCompat.setTint(wrappedDrawable, color);
autoCompleteTextView.setBackgroundDrawable(wrappedDrawable);
}
and in Activity.onCreate:
setStyleForTextForAutoComplete(getResources().getColor(R.color.greyLight));
autoCompleteTextView.setOnFocusChangeListener((v, hasFocus) -> {
if(hasFocus) {
setStyleForTextForAutoComplete(getResources().getColor(R.color.blue));
} else {
if(autoCompleteTextView.getText().length() == 0) {
setStyleForTextForAutoComplete(getResources().getColor(R.color.greyLight));
}
}
});
If you want to change the bar/line color and the hint text color of the TextInputLayout (what the accent color normally is), then just create this style:
<style name="MyStyle">
<item name="colorAccent">#color/your_color</item>
</style>
Then apply it to your TextInputLayout as a theme:
<android.support.design.widget.TextInputLayout
...
app:theme="#style/MyStyle" />
This basically sets a theme (not style) to one view (as opposed to the whole activity).
A TextinputLayout is not a view, but a Layout, as very nicely described by Dimitrios Tsigouris in his blog post here. Therefore, you don't need a Style, which is for Views only, but use a Theme. Following the blog post, I ended up with the following solution:
Start in your styles.xml with
<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">
<!-- reference our hint & error styles -->
<item name="android:textColor">#color/your_colour_here</item>
<item name="android:textColorHint">#color/your_colour_here</item>
<item name="colorControlNormal">#color/your_colour_here</item>
<item name="colorControlActivated">#color/your_colour_here</item>
<item name="colorControlHighlight">#color/your_colour_here</item>
</style>
And in your layout add
<com.google.android.material.textfield.TextInputLayout
android:theme="#style/TextInputLayoutAppearance"
...
<style name="Widget.Design.TextInputLayout" parent="android:Widget">
<item name="hintTextAppearance">#style/TextAppearance.Design.Hint</item>
<item name="errorTextAppearance">#style/TextAppearance.Design.Error</item>
</style>
You can override this style for layout
And also you can change inner EditText-item style too.
<style name="EditScreenTextInputLayoutStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#color/actionBar_background</item>
<item name="colorControlActivated">#color/actionBar_background</item>
<item name="colorControlHighlight">#color/actionBar_background</item>
<item name="colorAccent">#color/actionBar_background</item>
<item name="android:textColorHint">#color/actionBar_background</item>
</style>
apply this style to TextInputLayout
I used all of the above answers and none worked. This answer works for API 21+. Use app:hintTextColor attribute when text field is focused and app:textColorHint attribute when in other states. To change the bottmline color use this attribute app:boxStrokeColor as demonstrated below:
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeColor="#color/colorAccent"
app:hintTextColor="#color/colorAccent"
android:textColorHint="#android:color/darker_gray"
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
It works for AutoCompleteTextView as well. Hope it works for you:)
Works for me. If you trying EditText with Label and trying change to underline color use this. Change to TextInputEditText instead EditText.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/editTextTextPersonName3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_16sdp"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginRight="#dimen/_8sdp"
android:textColorHint="#color/white"
app:layout_constraintEnd_toStartOf="#+id/guideline3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#color/white"
android:hint="Lastname"
android:textSize="#dimen/_14sdp"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#color/white" />
</com.google.android.material.textfield.TextInputLayout>
Change line color of TextInputLayout + TextInputEditText
colors.xml
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#color/lineColor</color>
styles.xml
<style name="TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="boxStrokeColor">#color/lineColor</item>
<item name="android:textColorHint">#color/hintColor</item>
<item name="boxStrokeWidth">1dp</item>
<item name="boxBackgroundColor">#color/backgroundColor</item>
</style>
<style name="TextInputEditText" parent="ThemeOverlay.MaterialComponents.TextInputEditText.FilledBox.Dense">
<item name="android:textColor">#color/black</item>
</style>
layout.xml
<com.google.android.material.textfield.TextInputLayout
style="#style/TextInputLayout"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputEditText
style="#style/TextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
You can change the label color of TextInputLayout by using app:hintTextAppearance attribute in TextInputLayout.
<android.support.design.widget.TextInputLayout
android:id="#+id/inputlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextAppearance.App.TextInputLayout">
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="#string/email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:paddingStart="5dp"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
Style:
<style name="TextAppearance.App.TextInputLayout"
parent="#android:style/TextAppearance">
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">20sp</item>
</style>
To change edittext underline color, you can use android:backgroundTint
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
android:backgroundTint="#android:color/holo_red_light" />
Create style as mentioned below
<style name="text_input_layout_style">
<item name="colorControlNormal">#color/primary</item>
<item name="colorControlActivated">#color/primary</item>
<item name="colorControlHighlight">#color/primary</item>
</style>
and apply it to your TextInputLayout as android:theme="#style/text_input_layout_style"
And definitely will work for you all.
I needed to change the bottom line color of a TextInputEditText inside a TextInputLayout and then the other answers didn't work out. I finally solved it by setting the colorOnSurface for the TextInputLayouts theme. I'll leave my code here in case it helps someone else.
XML:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme=""#style/TextInputLayoutStyle"">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.te`tfield.TextInputLayout>
Style:
<style name="TextInputLayoutStyle">
<item name="colorOnSurface">#0ff</item>
</style>
XML
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/activity_profile_textInputLayout_mobile"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:hint="Mobile Number"
app:theme="#style/EditBoxColor">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/activity_profile_textInputEditText_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="10"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
Style
<style name="EditBoxColor" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="colorPrimary">#color/colorPurple</item>
<item name="colorPrimaryDark">#color/colorPurple3</item>
</style>
I want the Marquee effect on EVERY textview in my app...so I thought I put it in a style:
<style name="MyTextViewStyle" parent="#android:style/Widget.TextView">
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textSize">25sp</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
<item name="android:maxLines">1</item>
</style>
and set it in the app theme:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">#style/MyTextViewStyle</item>
</style>
this doe not work :(
Tried it directly on the TextView:
<TextView
android:ellipsize="marquee"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:maxLines="1"
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:fontFamily="sans-serif"
android:textAllCaps="true" />
This does work...
With the following condition: the style may NOT have the 'focusable' and 'focusableInTouchMode' options.
But without these uptions in the TextView example above, it will not scroll...
so I need these attributes, but am unable to get them to work via styles...anyone have an answer?
If focusable and focusableInTouchMode not working in Style then remove from Style.xml and add in every TextView
<style name="MyTextViewStyle" parent="#android:style/Widget.TextView">
<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textSize">25sp</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
<item name="android:maxLines">1</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">#style/MyTextViewStyle</item>
</style>
In Your layout.xml file.
<TextView
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:textAllCaps="true" />
Note : this will work if there is only one TextView in layout..
If you have many TextView as marquee in single layout then look at this example, Android-MarqueeView.
I'm guessing that android:ellipsize is not a text style element, so it is not inherited with android:textViewStyle.
Just add your MyTextViewStyle as a style to a TextView to check my guess. If this is the problem, you have to add the android:ellipsize attribute individually or in a style.
try this :
<TextView
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textAllCaps="true" />
and marquee effect will work only if text length is bigger than scree width.