I've used MaterialButton but my expected design not came. Below my xml code and style.
I've need white color of the background instead of the orange color, what I can do to achieve this. Please provide your suggestion.
// Material Design version I've used
implementation 'com.google.android.material:material:1.2.1'
**Color primary** means orange color.
<com.google.android.material.button.MaterialButton
android:id="#+id/btnWatchVideo"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="#string/watch_video"
android:textColor="#color/colorBlack"
android:visibility="visible"
app:strokeColor="#color/colorBlack"
app:strokeWidth="2dp" />
<style name="SliderThemeBlack" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:screenOrientation">portrait</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
Manifest:
<activity android:name="xxx"
android:theme="#style/SliderThemeBlack" android:windowSoftInputMode="stateHidden" />
use app:backgroundTint="#color/white" to your MaterialButton
Related
My AppTheme in styles.xml looks like this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
I set this in Manifest as:
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
According to https://material.io/develop/android/components/
The default color applied to my widgets should be the defined colorPrimary, but mine are picking up colorAccent as the default color. For example, this button:
<com.google.android.material.button.MaterialButton
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginEnd="56dp"
android:text="login"
app:cornerRadius="5dp"
app:elevation="0dp"
app:fontFamily="#font/gotham_bold" />
Am I missing a specific config for this project for this to have button to show colorPrimary and not colorAccent?
Use the Material Components Library 1.1.0 or later.
The default style of the MaterialButton is:
<style name="Widget.MaterialComponents.Button" parent="Widget.AppCompat.Button">
<item name="backgroundTint">#color/mtrl_btn_bg_color_selector</item>
<!-- .... -->
</style>
Starting from the version 1.1.0 the #color/mtrl_btn_bg_color_selector is based on the ?attr/colorPrimary:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_enabled="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
</selector>
In the version 1.0.0 the selector was based on ?attr/colorAccent:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorAccent" android:state_enabled="true"/>
<item android:color="#color/mtrl_btn_bg_color_disabled"/>
</selector>
in this case i believe only the color of text in your button has changed, it has the color value of textColorPrimary.
There is a chance that textColorPrimary and colorAccent are the same
First create btn_style in your styles.xml or themes.xml
<style name="btn_style" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">#null</item>
</style>
then in you layout apply the style and use the color or drawable that you want
<Button
android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:background="#color/YOUR_COLOR"
style="#style/btn_style"
android:text="Test"/>
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>
At the moment, I feel a little bit stupid.
Here's my problem :
I actually want to apply different styles for some buttons, different from my default button's style.
My styles.xml :
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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="CustomTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/CustomTheme.ActionBarStyle</item>
<item name="cardViewStyle">#style/CustomTheme.CardViewStyle</item>
<item name="buttonStyle">#style/CustomTheme.StandardButton</item>
</style>
<...>
<style name="CustomTheme.StandardButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">#drawable/ripple_button</item>
<item name="android:tint">#color/white</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.ConfirmButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">#drawable/ripple_button_confirm</item>
<item name="android:tint">#color/white</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.CancelButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">#drawable/ripple_button_cancel</item>
<item name="android:tint">#color/white</item>
<item name="android:elevation">8dp</item>
</style>
</resources>
In fact, I tried a lot of things with inheritance of my CustomTheme.ConfirmButton and CustomTheme.CancelButton.
What's changing from CustomTheme.StandardButton : the shape's color.
The ripple_button.xml is orange.
Then, I created two other ripple buttons, the first one is red (CancelButton), the second one is green (ConfirmButton).
By default, the <item name="buttonStyle">#style/CustomTheme.StandardButton</item> is applied.
But, in my activity, even when I declare a specific theme to my buttons, the default style is the only one applied.
Note : the both buttons are always visible in these activity.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_confirm_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_confirm"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#id/btn_cancel_reset"
android:layout_marginBottom="8dp"
style="#style/CustomTheme.ConfirmButton"/>
<Button
android:id="#+id/btn_cancel_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_cancel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="#id/btn_confirm_reset"
android:layout_marginBottom="8dp"
style="#style/CustomTheme.CancelButton"/>
</android.support.constraint.ConstraintLayout>
I tried to apply the "default" StandardButton theme manually for each button (and then by removing the line <item name="buttonStyle">#style/CustomTheme.StandardButton</item> from my styles.xml but I still get the same behavior : all my buttons are always orange (and using StandardButton theme).
So I'm wondering where I fail / what I don't understand, or even if it's possible.
If a peaceful soul has an idea, some tips, I will be grateful (I can thank my hero with a french craft beer).
Have a great day, and thanks for reading.
Update your Button Style as below:
style.xml
<style name="CustomTheme.StandardButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="android:backgroundTint">#color/orange</item>
<item name="android:colorButtonNormal">#color/gray</item>
<item name="android:colorControlHighlight">#color/blue</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.ConfirmButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="android:backgroundTint">#color/orange</item>
<item name="android:colorButtonNormal">#color/gray</item>
<item name="android:colorControlHighlight">#color/blue</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.CancelButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="android:backgroundTint">#color/orange</item>
<item name="android:colorButtonNormal">#color/gray</item>
<item name="android:colorControlHighlight">#color/blue</item>
<item name="android:elevation">8dp</item>
</style>
You missed to append android: in item background.
To set Ripple effect you have to use android:colorControlHighlight because android:backgroundTint will take only color as input and drawable will not work. Here android:colorButtonNormal will give no effect because we have set backgroundTint. If you will remove backgroundTint, it will take color from android:colorButtonNormal
You have to set the theme in Button instead of style.
your_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_confirm_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_confirm"
android:textColor="#color/white"
android:theme="#style/CustomTheme.ConfirmButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#id/btn_cancel_reset"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn_cancel_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_cancel"
android:textColor="#color/white"
android:theme="#style/CustomTheme.CancelButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#id/btn_confirm_reset"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Hope it will work!!
I've been trying to change the color of the progressBar, and i've noticed it's using the accentColor (which is Blue in my case) and i've been trying to change it without luck.
Am I missing something?
This is in my styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="searchViewStyle">#style/AppTheme.SearchView</item>
<item name="editTextColor">#android:color/white</item>
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
<item name="actionOverflowButtonStyle">#style/AppTheme.OverFlowItem</item>
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<item name="colorAccent">#color/ColorPrimaryDark</item>
</style>
This is my element in the layout.xml
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="#style/Widget.AppCompat.ProgressBar"
android:id="#+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
My activity:
public class MainActivity extends android.support.v7.app.AppCompatActivity
If you want to change accent color for one specific view you need to create style own style and set it to the view using android:theme attribute.
UPDATED
<style name="CustomProgressBarTheme" parent="Widget.AppCompat.ProgressBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryCutom</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkCustom</item>
<item name="colorAccent">#color/colorAccentCustom</item>
</style>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="#style/CustomProgressBarTheme"
android:id="#+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
try this
progressBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.ColorPrimaryDark), Mode.SRC_IN);
Since you have colorAccent with that color, you will need to change the ProgressBar's color with this:
android:progressBackgroundTint="#a31212" // your color
As the doc says:
Tint to apply to the progress indicator background.
Finally:
<ProgressBar
android:id="#+id/progressBar01"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="120dp"
android:progressBackgroundTint="#a31212" />
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>