Kotlin remove button’s background tint

I asume you are using a normal Button and then you set the style, don’t do it:

style="@style/Widget.AppCompat.Button.Colored"

Or maybe you are using a MaterialButton.

Anyway, the documentation says to don’t change the background:

All attributes from MaterialButton are supported. Do not use the android:background attribute. MaterialButton manages its own background drawable, and setting a new background means MaterialButton can no longer guarantee that the new attributes it introduces will function properly. If the default background is changed, MaterialButton cannot guarantee well-defined behavior.

If you want to use a custom background, as I see you have a drawable for this purpose, use just a normal Button.

<Button
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/myBackground"/>

Edit:

Your theme style it’s making the button to be a MaterialButton so now you can do two things:

-> You can change the full theme to a normal one:

<style name="Theme.TestFragmentUpdate" parent="Theme.AppCompat.Light.DarkActionBar">

This will change the full theme of your app.

-> You can change just the button theme

<resources xmlns:tools="http://schemas.android.com/tools">
        <!-- Base application theme. -->
        <style name="Theme.TestFragmentUpdate" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
            <!-- Primary brand color. -->
            <item name="colorPrimary">@color/bluish_grey</item>
            <item name="colorPrimaryVariant">@color/dark_teal</item>
            <item name="buttonStyle">@android:style/Widget.Button</item>
    
    <!--        <item name="colorOnPrimary">@color/black</item>-->
            <!-- Secondary brand color. -->
    <!--        <item name="colorSecondary">@color/teal_200</item>-->
    <!--        <item name="colorSecondaryVariant">@color/teal_200</item>-->
    <!--        <item name="colorOnSecondary">@color/black</item>-->
            <!-- Status bar color. -->
            <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
            <!-- Customize your theme here. -->
        </style>
    </resources>

Also, I think it could work that you set this concret style (The default Style) to the button and after just set the background you need so you don’t modify the full theme:

<Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       style="@android:style/Widget.Button"
       android:background="@drawable/myBackground"/>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top