This is how I set my buttons.
<Button
android:id="#+id/button_login"
style="#style/ButtonStyle"
android:text="#string/button_login" />
This is my style on values folder.
<style name="ButtonStyle" parent="ButtonStyleBase" />
<style name="ButtonStyleBase">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">#dimen/padding</item>
<item name="android:textSize">#dimen/font_regular</item>
<item name="android:textColor">#color/text_regular</item>
<item name="android:background">#drawable/shape_clickable</item>
</style>
And this is my style on values-v21 folder
<style name="ButtonStyle" parent="ButtonStyleBase">
<item name="textAllCaps">false</item>
<item name="android:textColor">#000000</item>
</style>
But the text is always uppercase on buttons. If I set it directly on the button it will get back to normal, though. I changed the color to see if the style for api 21 was being used and it was, the button text color changed to black on api 21. I know the default theme sets textAllCaps as true for buttons because google thought it would be super-duper-cool, but shouldn't it prioritize my style?
Edit: neverming, I forgot to write "android:" on the style.
I had the same issue and this is what worked for me:
<style name="Theme.CustomTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textAppearanceButton">#style/CustomTheme.ButtonTextAppearance</item>
</style>
<style name="CustomTheme.ButtonTextAppearance" parent="#style/Base.TextAppearance.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
Hope this helps.
In styles.xml
Include the button style in your AppTheme(Which will be using in Application or Activity)
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:buttonStyle">#style/MyButton</item>
</style>
create button style
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
If you found any issue please let me know.
Make sure that the following line does not say "android:" before "textAllCaps"
<item name="textAllCaps" tools:targetApi="ice_cream_sandwich">false</item>
Your style on values-v21 folder its correct
<style name="ButtonStyle" parent="ButtonStyleBase">
<item name="textAllCaps">false</item>
<item name="android:textColor">#000000</item>
</style>
but same time Api level above 21 your style paste on values-v19 and also style folder xml
Related
How can i change the text color of all the button in my app ? right now the only think that work is to do :
<style name="MyTheme" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:textColor">#ff0000</item>
</style>
but i m a little worried to use android:textColor who seam to not only impact the button
I try this but it's didn't work :
<style name="BBButtonColor" parent="#android:style/Widget.Button">
<item name="android:textColor">#ff0000</item>
</style>
<style name="BBButtonStyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#ff0000</item>
</style>
<style name="BBBorderlessButtonStyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#ff0000</item>
</style>
<style name="MyTheme" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:textAppearanceButton">#style/BBButtonColor</item>
<item name="android:buttonStyle">#style/BBButtonStyle</item>
<item name="android:borderlessButtonStyle">#style/BBBorderlessButtonStyle</item>
<item name="android:colorButtonNormal">#ff0000</item>
</style>
It's mostly the color of button inside popup dialog that i want to change
Loki, you can try this. This should change the color of all buttons in your app.
<style name="BBButtonColor" parent="android:Widget.Button">
<item name="android:textColor">#FF0000</item>
</style>
You were trying to use #android:style/Widget.Button, instead use android:Widget.Button and check. Let me know if this works.
You can try this :
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:buttonStyle">#style/ButtonColor</item>
<item name="colorButtonNormal">#color/colorname</item>
</style>
<style name="ButtonColor" parent="#android:style/Widget.Button">
<item name="android:textColor">#color/colorname</item>
</style>
and/change this line in Manifest file :
android:theme="#style/AppTheme.Base
You should create new style for buttons, something like that:
<style name="optionsButton">
<item name="android:layout_width">70dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/black</item>
<item name="android:textSize">15sp</item>
</style>
Now you can set this style for every button you want in layout xml, for example:
<Button
android:id="#+id/payCashBtn"
style="#style/optionsButton"
android:text="Cash" />
You can see I set layout_width and height in style, so all my buttons which use this style will have same parameters, but you can set different values for every button, or create multiple styles if you used it more than once. I hope it will help you.
I am wanting to create a custom ToggleButton style, mainly so I can change the minimum height and text size depending on the screen size.
I have already done this for Button:
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="buttonStyle">#style/MyButtonStyle</item>
</style>
<style name="MyButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:minHeight">#dimen/button_min_height</item>
<item name="android:textSize">#dimen/button_text_size</item>
</style>
And I am now wanting to do a similar thing for ToggleButton. I have tried this...
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="buttonStyle">#style/MyButtonStyle</item>
<item name="android:buttonStyleToggle">#style/MyToggleButtonStyle</item>
</style>
<style name="MyToggleButtonStyle" parent="Widget.AppCompat.ToggleButton">
<item name="android:minHeight">#dimen/button_min_height</item>
<item name="android:textSize">#dimen/button_text_size</item>
</style>
...but Widget.AppCompat.ToggleButton doesn't exist. So what changes do I need to make so I can control the minimum height and text size of my ToggleButtons like I already do for Buttons?
I would prefer an approach similar to the above, not only for consistency but so I don't have to go through all my layout files and update the ToggleButtons' xml individually.
This works for me.
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="buttonStyle">#style/MyButtonStyle</item>
<item name="android:buttonStyleToggle">#style/MyToggleButtonStyle</item>
</style>
<style name="MyToggleButtonStyle" parent="android:Widget.Button.Toggle">
<item name="android:minHeight">#dimen/button_min_height</item>
<item name="android:textSize">#dimen/button_text_size</item>
</style>
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
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
I would like to change all color texts in my application.
So I wrote this code and I set my theme in the manifest:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
</style>
But only TextView texts are in white. I would like Button and EditText to be in white too.
Can anyone help me? Thank you in advance.
Your Theme:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
<item name="android:buttonStyle">#style/ButtonTheme</item>
</style>
And this is how you can set your Button Theme:
<style name="ButtonTheme" parent="android:style/Widget.Button">
<item name="android:textColor">#color/white</item>
</style>
And also do this with EditTexts etc.
I think most of the widget styles build off of these:
<item name="android:textColorPrimary">#android:color/primary_text_dark</item>
<item name="android:textColorSecondary">#android:color/secondary_text_dark</item>
<item name="android:textColorTertiary">#android:color/tertiary_text_dark</item>
<item name="android:textColorPrimaryInverse">#android:color/primary_text_light</item>
<item name="android:textColorSecondaryInverse">#android:color/secondary_text_light</item>
<item name="android:textColorTertiaryInverse">#android:color/tertiary_text_light</item>
<item name="android:textColorPrimaryDisableOnly">#android:color/primary_text_dark_disable_only</item>
<item name="android:textColorPrimaryInverseDisableOnly">#android:color/primary_text_light_disable_only</item>
<item name="android:textColorPrimaryNoDisable">#android:color/primary_text_dark_nodisable</item>
<item name="android:textColorSecondaryNoDisable">#android:color/secondary_text_dark_nodisable</item>
<item name="android:textColorPrimaryInverseNoDisable">#android:color/primary_text_light_nodisable</item>
<item name="android:textColorSecondaryInverseNoDisable">#android:color/secondary_text_light_nodisable</item>
<item name="android:textColorHint">#android:color/hint_foreground_dark</item>
<item name="android:textColorHintInverse">#android:color/hint_foreground_light</item>
<item name="android:textColorSearchUrl">#android:color/search_url_text</item>
Override the values as needed.
Assign color to button text
<Button android:textColor="#FFFFFF"></Button>