androidxmlbuttonborder

Android button border stay deafault after adding drawable file


I'm working on a project in android studio and I'm trying to change the border to my button. My default button when I just add it to my grid look like this:

enter image description here

After adding new XML file (called box_solid_border.XML) in the drawable file that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:width="4dp"
        android:color="#000000" />

</shape>

the result is that it's creating the next shape that I can see:

enter image description here

and that exactly what I want to add to my button.

when I come back to my XML at the main file and add to my button the next line:

enter image description here

as you can see in line 226 I'm adding the background that I just created for this button to the button. and near the line, there is the exact border that I want. but in the application, the button still stays the same as the default one with no border added to him. Like this:

enter image description here

Does someone know the reason that the drawable file doesn't affect the button? If I'm doing the same thing for a textView or something else its works perfectly fine, just the button looks like not affected by the drawable extension to him.

Thank you!


Solution

  • You need to add this attribute to your button:

    app:backgroundTint="@null"
    

    If it has both attributes android:background and app:backgroundTint(if you are using the default theme for your application, it has a default value), the color specified by app:backgroundTint will be cover on the shape of drawable.