Search code examples
androidxmlandroid-layoutandroid-themeandroid-styles

Android style dosen't work


I am trying to add a specific style for a button, the issue is that it's works in themes.xml when I write this :

themes.xml

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
     <item name="colorControlHighlight">@color/background</item>
    <item name="colorButtonNormal">@color/white</item>
   </style>

mylayout.xml

 <Button
    android:id="@+id/play"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:gravity="center"
    android:text="Play"
    android:textColor="@color/guillotine_background"
    android:textSize="25dp"
    android:textStyle="bold"/>

but I don't get the same result when I use this :

styles.xml

 <style name="MyColorButton" parent="AppTheme">
        <item name="colorControlHighlight">@color/background</item>
        <item name="colorButtonNormal">@color/white</item>
</style>

I added this line to the button tag in mylayout.xml

mylayout.xml

  style="@style/MyColorButton"

Isn't that must return the same result ?


Solution

  • colorControlHighlight and colorButtonNormal are theme attributes. They are for styles that are used as themes for an Activity. They are not attributes of a Button. If you want to use it on the Button but not the whole Activity, use android:theme attribute instead:

    <Button
        android:theme="@style/MyColorButton"
        ... />