Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why android:buttonStyle does not style buttons?

So, I have this weird issue: My app is very simple, main activity with just one button in it and custom theme for the activity set in the manifest.

I can confirm the theme works and is selected, as I can change activity background or font color e.g.

But when I try to style all Buttons on my activity, it does not work!

This is the styles.xml code I use:

<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>
        <item name="android:background">#0f0</item>
        <item name="android:buttonStyle">@style/btxs</item>
    </style>

    <style name="btxs" parent="@android:style/Widget.Button">
        <item name="android:textColor">#f00</item>
    </style>

</resources>

Background of activity is green (so theme works), but button is still default.

Is android:buttonStyle correct way of setting button style in theme?

for reference I paste also my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_below="@+id/textView"
        android:layout_toEndOf="@+id/textView"
        android:layout_marginTop="25dp" />
</RelativeLayout>
like image 935
michnovka Avatar asked Nov 17 '15 03:11

michnovka


1 Answers

An AppCompatActivity will use buttonStyle. I'm also assuming that you probably want to extend Base.Widget.AppCompat.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>
        <item name="android:background">#0f0</item>
        <item name="buttonStyle">@style/btxs</item>
    </style>

    <style name="btxs" parent="Base.Widget.AppCompat.Button">
        <item name="android:textColor">#f00</item>
    </style>

</resources>
like image 92
tachyonflux Avatar answered Oct 05 '22 20:10

tachyonflux