android material button cannot remove round corners - android

I need to remove round corners of all buttons in app and use flat background. preferably a color.
This is my style:
<style name="Component.MyTheme.Button" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#color/white_50</item>
<item name="backgroundTint">#color/black</item>
<item name="cornerRadius">#null</item>
</style>
and this is how I apply it in my theme.
<item name="materialButtonStyle">#style/Component.MyTheme.Button</item>
I want to change this
to this
EDIT : Ignore white bars at either ends of 2nd image.

set corner radius attibute to 0dp.
app:cornerRadius="0dp"
Like below code
<com.google.android.material.button.MaterialButton
android:id="#+id/button_filter_apply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/apply"
android:fontFamily="sans-serif"
android:textAllCaps="true"
android:textColor="#color/white"
android:textStyle="bold"
app:backgroundTint="#color/clear_blue"
app:cornerRadius="0dp"
app:layout_constraintBottom_toBottomOf="parent" />
Button looks like
EDIT : Ignore black bars on both side of the image

Just use:
<style name="Component.MyTheme.Button" parent="Widget.MaterialComponents.Button.TextButton">
...
<item name="cornerRadius">0dp</item>
</style>
or
<style name="MyButton" parent="Widget.MaterialComponents.Button.TextButton">
...
<item name="shapeAppearanceOverlay">#style/shapeAppearanceOverlay_noCorner</item>
</style>
<style name="shapeAppearanceOverlay_noCorner" parent="">
<item name="cornerSize">0dp</item>
</style>

As you said you would like to add themes to your button.
Can you please try adding 0.1 to your corner radius?

Related

Make Android ImageButton look like Button

The documentation for ImageButton says:
By default, an ImageButton looks like a regular Button
This is obviously wrong because when I put both into a layout:
<Button
android:id="#+id/button2"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_margin="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_margin="20dp"
app:layout_constraintStart_toStartOf="#+id/button2"
app:layout_constraintTop_toBottomOf="#+id/button2" />
and run it, it looks like this:
The Button has a color and a shadow while the ImageButton is just a gray rectangle (with round corners I think).
Unfortunately I don't understand at all how styles work. My main question though is how do I need to change the ImageButton's configuration to actually make it look like a regular Button.
Are you using material design? Your Button does not look like the regular button that default style is #style/Widget.AppCompat.Button, but like the material button, which default style is #style/Widget.MaterialComponents.Button. If you set the style of the Button to #style/Widget.AppCompat.Button, you will see it looks the same as the ImageButton with default style #style/Widget.AppCompat.ImageButton
This is #style/Widget.AppCompat.Button, you can see that it has been expanded on the basis of #style/Widget.AppCompat.Button:
<style name="Widget.MaterialComponents.Button" parent="Widget.AppCompat.Button">
<item name="enforceMaterialTheme">true</item>
<item name="android:background">#empty</item>
<item name="enforceTextAppearance">true</item>
<item name="android:textAppearance">?attr/textAppearanceButton</item>
<item name="android:textColor">#color/mtrl_btn_text_color_selector</item>
<item name="android:paddingLeft">#dimen/mtrl_btn_padding_left</item>
<item name="android:paddingRight">#dimen/mtrl_btn_padding_right</item>
<item name="android:paddingTop">#dimen/mtrl_btn_padding_top</item>
<item name="android:paddingBottom">#dimen/mtrl_btn_padding_bottom</item>
<item name="android:insetLeft">0dp</item>
<item name="android:insetRight">0dp</item>
<item name="android:insetTop">#dimen/mtrl_btn_inset</item>
<item name="android:insetBottom">#dimen/mtrl_btn_inset</item>
<item name="android:stateListAnimator" ns2:ignore="NewApi">#animator/mtrl_btn_state_list_anim</item>
<item name="cornerRadius">#null</item>
<item name="elevation">#dimen/mtrl_btn_elevation</item>
<item name="iconPadding">#dimen/mtrl_btn_icon_padding</item>
<item name="iconTint">#color/mtrl_btn_text_color_selector</item>
<item name="rippleColor">#color/mtrl_btn_ripple_color</item>
<item name="backgroundTint">#color/mtrl_btn_bg_color_selector</item>
<item name="shapeAppearance">?attr/shapeAppearanceSmallComponent</item>
</style>
So, you can customize a new style for ImageButton, and then add those new style attributes of material button to the custom style (mainly cornerRadius, elevation, and rippleColor)
or set the button's style to #style/Widget.AppCompat.Button, while will also make the ImageButton looks like the Button :P

Center text with the icon in textButton

Well the question is probably dumb AF, but I can't figure it out. How can i center this button? Tried gravity and paddings, not with a success
Button style:
<style name="Theme.Base.Jabotmobile.TextBT"
parent="Widget.MaterialComponents.Button.TextButton">
<item name="icon">#drawable/ic_baseline_add_24</item>
<item name="iconPadding">4dp</item>
<item name="android:textSize">14sp</item>
<item name="fontFamily">#font/open_sans_regular</item>
<item name="android:maxLines">1</item>
<item name="android:padding">0dp</item>
<item name="textAllCaps">false</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="iconGravity">start</item>
</style>
Button in layout:
<Button
android:id="#+id/cat_req_BT1"
style="#style/Theme.JaBotMobile.TextBT"
android:layout_width="155dp"
android:layout_height="42dp"
android:layout_marginStart="18dp"
android:layout_marginTop="16dp"
android:text="#string/category_req"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout4" />
Try to add this constraint to, it should be centered with this way
app:layout_constraintEnd_toEndOf="parent"
PS
I understand the problem now, Basically you want to center the button items (icon and text) vertically. Unfortunately I don't have solution for this case, instead of using style you can create a custom view component, with custom view component you can have more flexibility for customizations.

drawable start not working with material button

Here is the button :
<Button
android:id="#+id/btn_choose_photo"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_camera"
android:drawablePadding="8dp"
android:text="#string/image_picker_dialog_choose_image"
android:textAlignment="textStart" />
I am using material themes, so this will be inflated into a material button
drawableStart has no effect at all, however drawableEnd, bottom and top work just fine
When I make the button tag a text view, drawableStart works
It seems like a bug or maybe I am missing something ?
Edit: My app theme is as follows :
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!---colors-->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryVariant">#color/colorPrimaryVariant</item>
<item name="colorPrimaryDark">#color/colorPrimaryVariant</item>
<item name="colorSecondary">#color/colorSecondary</item>
<item name="colorSecondaryVariant">#color/colorSecondaryVariant</item>
<item name="colorAccent">#color/colorSecondary</item>
<!--
<item name="android:colorBackground">#color/colorBackground</item>
-->
<!--components-->
<item name="textInputStyle">#style/text_input_layout_style</item>
<item name="bottomSheetDialogTheme">#style/bottom_sheet_dialog_theme</item>
<item name="spinnerStyle">#style/spinner_style</item>
<item name="android:spinnerStyle">#style/spinner_style</item>
<item name="android:toolbarStyle">#style/toolbar_style</item>
<item name="toolbarStyle">#style/toolbar_style</item>
<item name="actionOverflowButtonStyle">#style/overflow_button_style</item>
<item name="android:actionOverflowButtonStyle">#style/overflow_button_style</item>
</style>
You should use app:icon like this:
In the layout:
<Button
...
app:icon="#drawable/ic_camera"
style="#style/Widget.MaterialComponents.Button.TextButton"
/>
It is displayed at the start, before the text label. You can change icon gravity, tint or size.
For more information
Using
android:drawableLeft
will solve the problem, but will not give you RTL(Right to left) support. If your end user uses a different language which follow RTL, then your Button will not support it.
Are you managing the Button's property in the Activity or Fragment, as technically speaking,
android:drawableStart
should work.
You can change to "App compat button"
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/continuar_anonimo_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
app:backgroundTint="#color/greenPrimary"
android:background="#drawable/corner_boton_outline"
android:text="Continuar anonimamente"
android:paddingLeft="15dp"
android:drawableStart="#drawable/ic_google_color"
style="?android:textAppearanceSmall"/>
Use android:drawableLeft
android:drawableLeft="#drawable/ic_phone"
android:backgroundTint="#android:color/white"

Material Raised Button with Default Background

I am trying to create a button whose text color is the colorAccent and whose background color is the default background color.
It looks like this:
I have tried default styles, but non of them have worked. Currently I have something like this but doesn't work:
styles.xml :
<style name="AppTheme.ButtonRaised" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#android:color/transparent</item>
<item name="android:textColor">#color/colorAccent</item>
</style>
And layout:
<Button
app:theme="#style/AppTheme.ButtonRaised"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date" />
And I am getting something like this:
I am not getting any effect of style or theme here. I have also tried with style tag, but it doesn't work.
apply theme with a style like this
<style name="ThemeButtonBlue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorAccent">#color/colorPrimary</item>
<item name="colorButtonNormal">#android:color/transparent</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/colorPrimaryDark</item>
<item name="colorControlHighlight">#color/colorPrimary</item>
</style>
I am also struggling to do this effect. I could achieve something similar, but I don't know if its "material design approved".
I set the style to their button borderless colored and the elevation to 2dp because on material design they say that "Raised buttons have a default elevation of 2dp". But they don't give you xml layout examples which is annoying -_-
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
style="#style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:elevation="2dp"
android:text="Button"/>
Keep in mind that the elevation tag does not show a shadow pre Lollipop devices.

How to change the floating label color of TextInputLayout

With reference to the new TextInputLayout released by Google, how do I change the floating label text color?
Setting colorControlNormal, colorControlActivated, colorControlHighLight in styles does not help.
This is what I have now:
Try The Below Code It Works In Normal State
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hiiiii"
android:id="#+id/edit_id"/>
</android.support.design.widget.TextInputLayout>
In Styles Folder TextLabel Code
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/Color Name</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/Color Name</item>
<item name="colorControlNormal">#color/Color Name</item>
<item name="colorControlActivated">#color/Color Name</item>
</style>
Set To Main Theme of App,It Works Only Highlight State Only
<item name="colorAccent">#color/Color Name</item>
Update:
UnsupportedOperationException: Can't convert to color: type=0x2 in api 16 or below
Solution
Update:
Are you using Material Components Library
You can add below lines to your main theme
<item name="colorPrimary">#color/your_color</item> // Activated State
<item name="colorOnSurface">#color/your_color</item> // Normal State
or else do you want different colors in noraml state and activated state and with customization follow below code
<style name="Widget.App.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="materialThemeOverlay">#style/ThemeOverlay.App.TextInputLayout</item>
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item> //Changes the Shape Apperance
<!--<item name="hintTextColor">?attr/colorOnSurface</item>--> //When you added this line it will applies only one color in normal and activate state i.e colorOnSurface color
</style>
<style name="ThemeOverlay.App.TextInputLayout" parent="">
<item name="colorPrimary">#color/colorPrimaryDark</item> //Activated color
<item name="colorOnSurface">#color/colorPrimary</item> //Normal color
<item name="colorError">#color/colorPrimary</item> //Error color
//Text Appearance styles
<item name="textAppearanceSubtitle1">#style/TextAppearance.App.Subtitle1</item>
<item name="textAppearanceCaption">#style/TextAppearance.App.Caption</item>
<!--Note: When setting a materialThemeOverlay on a custom TextInputLayout style, don’t forget to set editTextStyle to either a #style/Widget.MaterialComponents.TextInputEditText.* style or to a custom one that inherits from that.
The TextInputLayout styles set materialThemeOverlay that overrides editTextStyle with the specific TextInputEditText style needed. Therefore, you don’t need to specify a style tag on the edit text.-->
<item name="editTextStyle">#style/Widget.MaterialComponents.TextInputEditText.OutlinedBox</item>
</style>
<style name="TextAppearance.App.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">
<item name="fontFamily">#font/your_font</item>
<item name="android:fontFamily">#font/your_font</item>
</style>
<style name="TextAppearance.App.Caption" parent="TextAppearance.MaterialComponents.Caption">
<item name="fontFamily">#font/your_font</item>
<item name="android:fontFamily">#font/your_font</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">4dp</item>
</style>
Add the below line to your main theme or else you can set style to textinputlayout in your xml
<item name="textInputStyle">#style/Widget.App.TextInputLayout</item>
<style name="TextAppearance.App.TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/red</item>
<item name="android:textSize">14sp</item>
</style>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/gray" //support 23.0.0
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout" >
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint" />
</android.support.design.widget.TextInputLayout>
Found the answer, use android.support.design:hintTextAppearance attribute to set your own floating label appearance.
Example:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:hintTextAppearance="#style/TextAppearance.AppCompat">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"/>
</android.support.design.widget.TextInputLayout>
how do I change the floating label text color?
With the Material Components library you can customize the TextInputLayout the hint text color using (it requires the version 1.1.0)
In the layout:
app:hintTextColor attribute : the color of the label when it is collapsed and the text field is active
android:textColorHint attribute: the color of the label in all other text field states (such as resting and disabled)
<com.google.android.material.textfield.TextInputLayout
app:hintTextColor="#color/mycolor"
android:textColorHint="#color/text_input_hint_selector"
.../>
extending a material style Widget.MaterialComponents.TextInputLayout.*:
<style name="MyFilledBox" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="hintTextColor">#color/mycolor</item>
<item name="android:textColorHint">#color/text_input_hint_selector</item>
</style>
The default selector for android:textColorHint is:
<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>
You don't need to use android:theme="#style/TextInputLayoutTheme" to change the floating label color, since it's going to affect to the entire theme for the small TextView used as label. Instead, you could use app:hintTextAppearance="#style/TextInputLayout.HintText" where:
<style name="TextInputLayout.HintText">
<item name="android:textColor">?attr/colorPrimary</item>
<item name="android:textSize">#dimen/text_tiny_size</item>
...
</style>
Let me know if the solution works :-)
Ok, so, I found this answer very helpful and thanks to all the people who contributed. Just to add something, though. The accepted answer is indeed the correct answer...BUT...in my case, I was looking to implement the error message below the EditText widget with app:errorEnabled="true" and this single line made my life difficult. it seems that this overrides the theme I chose for android.support.design.widget.TextInputLayout, which has a different text color defined by android:textColorPrimary.
In the end I took to applying a text color directly to the EditText widget. My code looks something like this:
styles.xml
<item name="colorPrimary">#color/my_yellow</item>
<item name="colorPrimaryDark">#color/my_yellow_dark</item>
<item name="colorAccent">#color/my_yellow_dark</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#color/dark_gray</item>
<item name="android:windowBackground">#color/light_gray</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:textColorHint">#color/dark_gray</item>
<item name="android:colorControlNormal">#android:color/black</item>
<item name="android:colorControlActivated">#android:color/white</item>
And my widget:
<android.support.design.widget.TextInputLayout
android:id="#+id/log_in_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<EditText
android:id="#+id/log_in_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#android:color/black"
android:ems="10"
android:hint="#string/log_in_name"
android:inputType="textPersonName" />
</android.support.design.widget.TextInputLayout>
Now it displays black text color instead of the textColorPrimary white.
Programmatically you can use:
/* Here you get int representation of an HTML color resources */
int yourColorWhenEnabled = ContextCompat.getColor(getContext(), R.color.your_color_enabled);
int yourColorWhenDisabled = ContextCompat.getColor(getContext(), R.color.your_color_disabled);
/* Here you get matrix of states, I suppose it is a matrix because using a matrix you can set the same color (you have an array of colors) for different states in the same array */
int[][] states = new int[][]{new int[]{android.R.attr.state_enabled}, new int[]{-android.R.attr.state_enabled}};
/* You pass a ColorStateList instance to "setDefaultHintTextColor" method, remember that you have a matrix for the states of the view and an array for the colors. So the color in position "colors[0x0]" will be used for every states inside the array in the same position inside the matrix "states", so in the array "states[0x0]". So you have "colors[pos] -> states[pos]", or "colors[pos] -> color used for every states inside the array of view states -> states[pos] */
myTextInputLayout.setDefaultHintTextColor(new ColorStateList(states, new int[]{yourColorWhenEnabled, yourColorWhenDisabled})
Explanation:
Get int color value from a color resource (a way to present rgb colors used by android).
I wrote ColorEnabled, but really it should be, for this answer, ColorHintExpanded & ColorViewCollapsed. Anyway this is the color you will see when the hint of a view "TextInputLayout" is on Expanded or Collapsed state; you will set it by using next array on function "setDefaultHintTextColor" of the view.
Reference:
Reference for TextInputLayout - search in this page the method
"setDefaultHintTextColor" for more info
Looking to docs above you can see that the functions set the colors for Expanded & Collapsed hint by using a ColorStateList.
ColorStateList docs
To create the ColorStateList I first created a matrix with the states I want, in my case state_enabled & state_disabled (whose are, in TextInputLayout, equals to Hint Expanded and Hint Collapsed [I don't remember in which order lol, anyway I found it just doing a test]).
Then I pass to the constructor of the ColorStateList the arrays with int values of color resources, these colors have a correspondences with the states matrix (every element in colors array correspond to the respective array in states matrix at same position). So the first element of the colors array will be used as color for every state in the first array of the states matrix (in our case the array has only 1 element: enabled state = hint expanded state for TextInputLayut).
Last things states have positive / negative values, and you have only the positive values, so the state "disabled" in android attrs is "-android.state.enabled", the state "not focused" is "-android.state.focused" ecc.. ecc..
Hope this is helpful.
Bye have a nice coding (:
I suggest you make style theme for TextInputLayout and change only accent color. Set parent to your app base theme:
<style name="MyTextInputLayout" parent="MyAppThemeBase">
<item name="colorAccent">#color/colorPrimary</item>
</style>
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#style/MyTextInputLayout">
In the latest version of the support library (23.0.0+), TextInputLayout takes the following attribute in XML to edit the floating label color: android:textColorHint="#color/white"
Instead of Brahmam Yamani answer I prefer to use Widget.Design.TextInputLayout as parent. That ensures, that all required items are present, even if not all items are overwritten. In Yamanis answer, the app will crash with an unresolvable resource, if setErrorEnabled(true) is called.
Simply change the style to the following:
<style name="TextLabel" parent="Widget.Design.TextInputLayout">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/Color Name</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/Color Name</item>
<item name="colorControlNormal">#color/Color Name</item>
<item name="colorControlActivated">#color/Color Name</item>
</style>
To change color of hint and edit text underline color : colorControlActivated
To change character counter color : textColorSecondary
To change error message color : colorControlNormal
To change password visibility button tint : colorForeground
For more info on TextInputLayout read http://www.zoftino.com/android-textinputlayout-tutorial
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorControlActivated">#e91e63</item>
<item name="android:colorForeground">#33691e</item>
<item name="colorControlNormal">#f57f17</item>
<item name="android:textColorSecondary">#673ab7</item>
</style>
In my case I added this "app:hintTextAppearance="#color/colorPrimaryDark"in my TextInputLayout widget.
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.
So I set android:hint and app:hintTextColor on TextInputLayout, not on TextInputEditText and it worked.
This is simple but the developer gets confused due to multiple views having the same attributes in different configurations/namespaces.
In the case of the TextInputLayout we have every time a different view and with params either with TextInputEditText or directly to TextInputLayout.
I was using all the above fixes:
But I found that I was using
app:textColorHint="#color/textcolor_black"
actually i should be using
android:textColorHint="#color/textcolor_black"
As an attribute of TextinputLayout
textcolor_black.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/black_txt" android:state_enabled="true" />
<item android:color="#color/black_txt" android:state_selected="true" />
<item android:color="#color/txtColorGray" android:state_selected="false" />
<item android:color="#color/txtColorGray" android:state_enabled="false" />
</selector>
Too many complicated solutions. Here is a one liner to change the color of the floating label.
<com.google.android.material.textfield.TextInputLayout
app:hintTextColor="#color/white"/>
In addition to change other attributes:
To change the box stroke color:
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeColor="#color/green"
To change the box stroke width:
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeWidth="1.5dp"
To change the edit TextInputEditText hint color:
<com.google.android.material.textfield.TextInputEditText
android:textColorHint="#color/white"
To change the TextInputEditText color:
<com.google.android.material.textfield.TextInputEditText
android:textColor="#color/white" />
you should change your colour here
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#FF4081</item>
<item name="android:windowBackground">#color/window_background</item>
</style>
Now, simply using colorAccent and colorPrimary will work perfectly.
I solve the problem.
This is Layout:
<android.support.design.widget.TextInputLayout
android:id="#+id/til_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/username"
>
<android.support.v7.widget.AppCompatEditText android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
This is Style:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorAccent">#color/pink</item>
<item name="colorControlNormal">#color/purple</item>
<item name="colorControlActivated">#color/yellow</item>
</style>
You should use your theme in application:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
to change color of the text label when you are focusing on it. i.e. typing in it. you have to add specify
<item name="android:textColorPrimary">#color/yourcolorhere</item>
Just a note:
You have to add all these implementations to your main theme.
Its Working for me .....
add hint color in TextInputLayout
<android.support.design.widget.TextInputLayout
android:textColorHint="#ffffff"
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edtTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
I tried using android:textColorHint in the android.support.design.widget.TextInputLayout it works fine.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/colorAccent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeActionLabel="Hello"
android:imeOptions="actionUnspecified"
android:maxLines="1"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
<style name="AppTheme2" parent="AppTheme">
<!-- Customize your theme here. -->
<item name="colorControlNormal">#fff</item>
<item name="colorControlActivated">#fff</item></style>
add this to styles and set TextInputLayout Theam to App2 and it will work ;)
<com.google.android.material.textfield.TextInputLayout
android:hint="Hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextInputLayoutHint">
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:paddingTop="#dimen/_5sdp"
android:paddingBottom="#dimen/_5sdp"
android:textColor="#000000"
android:textColorHint="#959aa6" />
</com.google.android.material.textfield.TextInputLayout>
res/values/styles.xml
<style name="TextInputLayoutHint" parent="">
<item name="android:textColorHint">#545454</item>
<item name="colorControlActivated">#2dbc99</item>
<item name="android:textSize">11sp</item>
</style>
Can use app:hintTextColor if you use com.google.android.material.textfield.TextInputLayout, try this
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/app_name"
app:hintTextColor="#android:color/white">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
Try The Below Code It Works In Normal State
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hiiiii"
android:id="#+id/edit_id"/>
</android.support.design.widget.TextInputLayout>
In Styles Folder TextLabel Code
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/Color Name</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/Color Name</item>
<item name="colorControlNormal">#color/Color Name</item>
<item name="colorControlActivated">#color/Color Name</item>
</style>
Because you must add colorControlNormal, colorControlActivated, colorControlHighLight items to main application theme:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlActivated">#color/yellow_bright</item>
<item name="colorControlNormal">#color/yellow_black</item>
</style>

Categories

Resources