I want to change TextInputLayout float hint text. Here is the solution I tried:
style.xml:
<style name="TextAppearence.App.TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorPrimary</item>
</style>
layout.xml:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout">
It works fine for some parts of app but not changes the hint color of some activities or fragments. I wonder How is it possible that a piece of code can effect some activities but not on the others.
Any idea?
Add <item name="colorAccent">#color/theme_color_blue</item> line in your style.xml like this
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/theme_color_blue</item>
<item name="colorAccent">#color/theme_color_blue</item>
<item name="android:textColorPrimary">#color/colorTextPrimary</item>
<item name="android:textColorSecondary">#color/colorTextSecondary</item>
</style>
you should use textColorHint item for your AppTheme style:
<item name="android:textColorHint">#color/yourcolor</item>
Related
I use this in my theme now I am wondering if possible without using theme either programmatically changing colors of textinputlayout
or I can change in xml still without using theme, as I need to fetch colors dynamically and I write code for that or do databinding in xml.
<item name="colorControlActivated">#color/primaryTextColor</item>
<item name="android:textColorHint">#color/primaryTextColor</item>
<item name="android:textColor">#color/primaryTextColor</item>
<item name="android:editTextColor">#color/primaryTextColor</item>```
Yes, we can use setBackgroundColor().
But in your case I think you need to build your own style, here is an example:
Creating TextInputLayout Theme
Let's define a couple of text Styles that will be used as part of the theme. These styles correspond to the different texts used, such as the Hint and Error texts.
<style name="ErrorText" parent="TextAppearance.AppCompat">
<item name="android:textColor">#android:color/red</item>
<item name="android:textSize">16sp</item>
</style>
<style name="HintText" parent="TextAppearance.AppCompat">
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">14sp</item>
</style>
Then, we create our TextInputLayout theme, referencing the above:
<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">
<!-- reference our hint & error styles -->
<item name="hintTextAppearance">#style/HintText</item>
<item name="errorTextAppearance">#style/ErrorText</item>
<item name="android:textColor">#color/user_input_color</item>
<item name="android:textColorHint">#color/unfocused_color</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/blue</item>
<item name="colorControlHighlight">#color/green</item>
</style>
And for the last step, we build our layout.xml using the android:theme attribute with the style we defined above:
<android.support.design.widget.TextInputLayout
android:theme="#style/TextInputLayoutAppearance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_email"/>
</android.support.design.widget.TextInputLayout>
Style.xml File(AppTheme is the theme of my app and it is inheriting materiallightdarkactionbar theme)
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorForeground">#color/holo_orange_light</item>
<item name="android:buttonStyle">#style/newbuttonstyle</item>
</style>
<style name="newbuttonstyle" parent="#android:style/Widget.Button">
<item name="android:backgroundTint">#acd9e6</item>
</style>
</resources>
I am designing a calculator and this is the keypad for it.....rather than individually setting background tint for all the buttons I want to change the style of all my buttons in one go using style.xml....can i do so?
In this I am using buttonStyle and still it is not working
<item name="android:buttonStyle">#style/newbuttonstyle</item>
in your XML file
<Button
style="#style/MyButtonStyle"
android:id="#+id/btnSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="my button"/>
in style.xml file add this code.
<style name="ButtonStyle" parent="#android:style/Widget.Button">
<item name="android:layout_width">fill_parent</item>
<item name="android:textColor">#color/black</item>
<item name="android:textSize">15sp</item>
<item name="android:padding">10dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:gravity">center</item>
</style>
change Style items as per your requirements.
<style name="newbuttonstyle" parent="#android:style/Widget.Button">
<item name="android:background">#acd9e6</item>
</style>
I am using above code in my application and its working fine.i think set background instead of backgroundTint.
May be its working .
check this link:
ReferenceLink
and its some issue in tintbackground in lolipop.so you have to check in below lolipop.
You can follow this question, hope it will be work for you and clear your style portion:
Android Material Design Button Styles
So I have a spinner that I'm trying to apply a style to. I have a activity theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
And a spinner
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/entries"
I want the text of the spinner items to appear as white and to do so with xml styling. If I set android:textColor in AppTheme, everything works fine.
However this applies to other elements as well.
I have tried the following attribues in AppTheme. None of them have worked.
<item name="android:spinnerDropDownItemStyle">#style/SpinnerItem</item>
<item name="android:dropDownItemStyle">#style/SpinnerItem</item>
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
<style name="SpinnerItem">
<item name="android:textColor">#android:color/white</item>
</style>
Any help is appreciated.
You can change your AppTheme like this:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerStyle">#style/AppTheme.Spinner</item>
<item name="android:spinnerDropDownItemStyle">#style/AppTheme.DropDownSpinner</item>
</style>
<style name="AppTheme.Spinner" parent="Widget.AppCompat.Spinner">
<item name="android:textColor">#color/white</item>
</style>
<style name="AppTheme.DropDownSpinner" parent="Widget.AppCompat.DropDownItem.Spinner">
<item name="android:textColor">#color/white</item>
</style>
My problem is that I don't know how to change underline color of EditText - I have LG Nexus 5 (Android 6).
I would like to change normal underline color to white. I used all params like (style):
colorControlNormal
colorControlActivated
colorControlHighlight
textColorSecondary
colorPrimary
colorPrimaryDark
e.g.
<style name="FormFont" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">#dimen/form_text_size</item>
<item name="colorControlNormal">#c5c5c5</item>
</style>
but nothing seems to work (it only changes color when EditText us focused like in above pic).
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
</style>
The most efficient thing to do is to add the colorAccent attribute in your AppTheme style like this:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#color/colorAccent</item>
<item name="android:editTextStyle">#style/EditTextStyle</item>
</style>
<style name="EditTextStyle" parent="Widget.AppCompat.EditText"/>
The colorAccent attribute is used for widget tinting throughout the app and thus should be used for consistency
Try using android:backgroundTint="#yourUnderlineColor".
Only available for API 21 and higher.
To make it work in Android 6, create your custom theme in
res/values-v21/styles.xml .
<style name="FormFont" parent="#android:style/TextAppearance.Medium">
<item name="colorControlNormal">#c5c5c5</item>
</style>
<style name="FormFontWhite" parent="#android:style/TextAppearance.Medium">
<item name="colorControlNormal">#ffffff</item>
</style>
and apply then in your EditText
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/FormFont"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/FormFontWhite"/>
For more info check #reVerse answer .
Hope this helps!
<android.support.v7.widget.AppCompatEditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/cux_label_password"
android:inputType="textPassword"
app:theme="#style/editTextStyle" />
<style name="editTextStyle" parent="TextAppearance.AppCompat">
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorControlActivated">#FFFFFF</item>
<item name="colorControlHighlight">#FFFFFF</item>
</style>
I have values:styles.xml with:
<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/my_color</item>
<item name="android:textColor">#android:color/white</item>
</style>
and values-v21:styles.xml with:
<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button">
<item name="android:colorButtonNormal">#color/my_color</item>
<item name="android:textColor">#android:color/white</item>
</style>
And app style with
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/AppTheme.Button</item>
</style>
But the colors appears grey instead of #color/my_color
To customize one Button only set android:theme="#style/AppTheme.Button" to your Button.
<Button
android:theme="#style/AppTheme.Button"
/>
Define your style as you did in your question
<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/my_color</item>
</style>
[EDIT]
See GitHub demo here
Use Widget.AppCompat.Button.Colored as a parent for your style.
<style name="RedButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:textColor">#color/white</item>
<item name="colorButtonNormal">#color/red</item>
</style>
Use android:theme, not style in buttons definitions:
<Button android:theme="#style/RedButton"/>
See AppCompat v21 > Theming and Android Support Library v22.1 - AppCompat blog posts.
(note on second post, android:theme is supported on API11-, it just doesn't do automatic inheritance from parent, you will have to specify it on each child, not an issue here but worth mentioning - see Chris Banes' post on that).
Put the xml line below in your "AppTheme" xml, rather than trying to set it from the "AppTheme.Button". This works for me on v22.1.1 with non-lollipop devices. I'm guessing this is a bug because your solution above works fine for lollipop.
<item name="colorButtonNormal">#color/my_color</item>
Ensure your Activity is extending AppCompatActivity, otherwise it won't handle appCompat styles properly.
class: android.support.v7.app.AppCompatActivity
Gradle: compile 'com.android.support:appcompat-v7:23.0.1'
Use:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="buttonStyle">#style/AppTheme.Button</item>
</style>
remove the android:
That works:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- android:buttonStyle for v21+ and buttonStyle for the rest -->
<item name="buttonStyle">#style/MyCustomButton</item>
<item name="android:buttonStyle">#style/MyCustomButton</item>
<item name="colorButtonNormal">#color/my_color</item>
</style>
<style name="MyCustomButton" parent="Base.Widget.AppCompat.Button">
<item name="android:textColor">#ffffff</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>
colorButtonNormal can be set in the theme style. To change the text color, size or any other feature of the button you can create a style and then using buttonStyle (less than v21) or android:buttonStyle (v21+) in the the theme style to set the button style.
v21/styles.xml
<style name="AppTheme.BlueButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:colorButtonNormal">#color/blue</item>
<item name="android:textColor">#color/text_white</item>
</style>
styles.xml
<style name="AppTheme.BlueButton" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/blue_tint</item>
<item name="android:textColor">#color/text_white</item>
</style>
Initially I'm too facing this problem. After making correction like above I got correct UI button
It seems to be a bug on Android framework that we can not change customize colorButtonNormal with Widget.AppCompat.Button theme.
A workaround solution is to define another custom AppCompat theme and use colorAccent to set colorButtonNormal.
There are two following steps.
1.Define another theme for your custom button.
<resources>
<!-- 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>
<!-- Custom button theme. -->
<style name="CustomButtonTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Set your desired button color here. -->
<item name="colorAccent">#color/red</item>
<item name="buttonStyle">#style/Widget.AppCompat.Button.Colored</item>
</style>
</resources>
2.Apply button theme in layout.
<Button android:theme="#style/CustomButtonTheme"/>
Hi I think the parent widget you used might be not correct one, it should android:Widget.Button for API version 21 or earlier version, for later version 21 or above you should use `android:Widget.Material.Button. Let say you have default style should look see below.
res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/AppTheme.Button</item>
</style>
<style name="AppTheme.Button" parent="android:Widget.Button">
<item name="android:background">#color/my_color</item>
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
For API version 21 the resource style file should look like (res/values-v21/style.xml)
<resources>
<style name="AppTheme.Button" parent="android:Widget.Material.Button">
<item name="android:background">#color/my_color</item>
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
Thank you Let me know if you have any question.
In case you wonder why colorButtonNormal is not picked up as defined for disabled buttons, you might also need to set android:disabledAlpha to 1.0 in your theme, otherwise your color will by default blend into the button's background. Example:
<style name="MyButtonTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:disabledAlpha">1.0</item>
<item name="colorButtonNormal">#color/my_solid_disabled_color</item>
<item name="colorAccent">#color/my_solid_accent_color</item>
<item name="buttonStyle">#style/my_button_style</item>
</style>
Try buttonStyle instead of android:buttonStyle, since this is AppCompat attribute pre Lollipop, so it should be without android prefix