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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With