首页 > 解决方案 > Why is my drawable button layout not being applied to the button as a background?

问题描述

I have created a buttonbg.xml file to give a button a round shape with a custom color. Here's how the xml code looks like,

<stroke
    android:color="#69B9F9"
    android:width="3dp" />

<corners
    android:radius="200dp" />

But when i apply this xml as a background to the button,

<Button android:id="@+id/loginButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="59dp"
    android:layout_marginEnd="61dp"
    android:layout_marginBottom="227dp"
    android:background="@drawable/button_bg"
    android:text="LOGIN"
    android:textSize="22sp" />

Nothing happens,

Button Image

Please help me out!

标签: androidxmlbuttonlayout

解决方案


Add this to your button

app:backgroundTint="@null" 

Also in your question you've written

I have created a buttonbg.xml file

and in your code you've written button_bg.xml. Please check if the typo exist in your code or just in the question itself


推荐阅读