2

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?

img

In this I am using buttonStyle and still it is not working

<item name="android:buttonStyle">@style/newbuttonstyle</item>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Mini Agarwal
  • 21
  • 1
  • 1
  • 8
  • 3
    Possible duplicate of [How do I apply a style to all buttons of an Android application](http://stackoverflow.com/questions/2410836/how-do-i-apply-a-style-to-all-buttons-of-an-android-application) – K.Sopheak Oct 12 '16 at 03:46
  • try this: http://stackoverflow.com/questions/17192104/changing-button-style-in-the-whole-application – sneha desai Oct 12 '16 at 04:02
  • You all are saying that i have to explicitly mention the style in the button itself then what is the use of this? @style/newbuttonstyle – Mini Agarwal Oct 12 '16 at 04:22

3 Answers3

2

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.

Rajesh Satvara
  • 3,842
  • 2
  • 30
  • 50
1
<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.

Community
  • 1
  • 1
dipali
  • 10,966
  • 5
  • 25
  • 51
0

You can follow this question, hope it will be work for you and clear your style portion: Android Material Design Button Styles

Community
  • 1
  • 1
Jamil Hasnine Tamim
  • 4,389
  • 27
  • 43