skip to Main Content

I’m trying to assign a theme to a button with a custom background. It looks simply like this:

<style name="button">
    <item name="android:background">@drawable/buttonbackground</item>
</style>‌

<Button android:theme="@style/button"/>

The button keeps it’s original background, but for TextView, for example, it works.

<TextView android:theme="@style/button"/>

Where’s the problem?

2

Answers


  1. Chosen as BEST ANSWER

    Well, it was a very simple solution, just use style instead of android:theme. I just didn't know it existed.


  2. change your app theme:

        <style name="Theme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
            .....
        </style>
    

    use @style/Theme in the AndroidManifest.xml:

        <application
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/Theme"
            >
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search