2

I tried to make a custom button style for all my buttons in my app like in this question/solution. I want to do it like that because I dont want to add:

android:style="@style/MyButtonStyle"

to every button

My current code.

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:buttonStyle">@style/MyButtonStyle</item>
</style>

<!-- Button style. -->
<style name="MyButtonStyle" parent="android:style/Widget.Button">
    <item name="android:textColor">@color/ColorTextIcons</item>
    <item name="android:background">@color/ColorAccent</item>
</style>

Manifest

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

In the preview in android studio it looks good, however when I run the app i get a default button style. As far as I know its the same as the accepted answer with 120 upvotes.

What is wrong with the code and why is it showing different in android studio?

Preview in android studio.

enter image description here

My device (s5 mini android 4.4.2)

enter image description here NOTE I dont apply any different styles/themes to the activitys

Community
  • 1
  • 1
Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169

2 Answers2

0

Try one among these:

Apply theme to activity/application:

android:theme="@style/AppTheme"

Apply style to button:

style="@style/MyButtonStyle"

If you are using compat library you can get errors depending on your android version:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:buttonStyle">@style/MyButtonStyle</item>
    <item name="buttonStyle">@style/MyButtonStyle</item>
</style>

<style name="MyButtonStyle" parent="android:style/Widget.Button">
    <item name="android:textColor">@color/ColorTextIcons</item>
    <item name="android:background">@color/ColorAccent</item>
    <item name="textColor">@color/ColorTextIcons</item>
    <item name="background">@color/ColorAccent</item>
</style>
Juan Aguilar Guisado
  • 1,687
  • 1
  • 12
  • 21
0

I think it should be

<style name="MyButtonStyle" parent="@android:style/Widget.Button">

and

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">

With the @android and the @style.

sonic
  • 1,894
  • 1
  • 18
  • 22