Home > front end >  background is not showing up on android studio button
background is not showing up on android studio button

Time:02-17

I have set it up to where my button's style is borderless and I'm using a drawable for the button background (android:background="@drawable/circle")

This is the code for the @drawable/circle file

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape = "rectangle">
            <corners android:radius="1000dp"/>
            <solid android:color="#263238"/>
        </shape>
    </item>
</selector>

and that color (#26338) does not appear on the button instead the button looks like this

what it looks like in design mode

In case you're wondering heres the XML code for the button

<Button
                android:id="@ id/clearBTN"
                style="@style/Widget.AppCompat.Button.Borderless"
                android:layout_width="0dp"
                android:layout_height="70dp"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/circle"
                android:backgroundTint="@color/red"
                android:fontFamily="@font/oswald_medium"
                android:text="@string/clear"
                android:textColor="#FFFFFF"
                android:textSize="24sp" />

When in reality it should be more like this color

this is the color I'm looking for

Some more additional info is that my button is in a TableRow inside of a tableLayout. Also when I try applying a backgroundTint it also does not work. Am using the latest version of android studio and I'm pretty sure everything else is up to date.


How can I fix this? Thanks.

CodePudding user response:

That is Button bug.

change Button to androidx.appcompat.widget.AppCompatButton

CodePudding user response:

use bellow xml for create button background.

<shape xmlns:android="http://schemas.android.com/apk/res/android">

      <corners android:radius="1000dp"/>
      <solid android:color="#263238"/>
     
</shape>

this code for use drawable with button.@drawable/circle is your background drawable name.

<Button
         android:id="@ id/clearBTN"
         android:layout_width="0dp"
         android:layout_height="70dp"
         android:layout_margin="5dp"
         android:layout_weight="1"
         android:background="@drawable/circle"
         android:fontFamily="@font/oswald_medium"
         android:text="@string/clear"
         android:textColor="#FFFFFF"
         android:textSize="24sp" />

CodePudding user response:

I had the same problem with Buttons.

use AppCompatButton instead using Button.

package : androidx.appcompat.widget.AppCompatButton

  • Related