Kartik
Kartik

Reputation: 2609

Configuring the drawable asset to have the same background colour as standard android background

This is my button layout

<TextView android:id="@+id/notification_button"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"

    android:paddingEnd="8dp"
    android:paddingStart="8dp"

    android:background="@drawable/blue_outlined_rect"

    android:ellipsize="end"
    android:gravity="center"
    android:maxLines="1"

    android:textAppearance="@style/TextAppearance"
    tools:text="View Item" />

The background is rendered by a drawable asset.

Drawable

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

    <stroke
        android:width="1dp"
        android:color="@color/color_blue" />
</shape>

As you can see, the button background is not the same as text background. I am using a drawable resource to render the blue outline for the rectangle

I want the button background to be the same as the view background. How can I achieve that?

I have tried changing the following attribute as follows

<solid android:color="?android:attr/background"/>

and

<solid android:color="?android:background"/>

I don't know what I am doing wrong.

Button

Upvotes: 0

Views: 43

Answers (1)

sanoJ
sanoJ

Reputation: 3128

One solution maybe you can use a transparent background for the button.

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

    <stroke
        android:width="1dp"
        android:color="@color/color_blue" />
</shape>

Upvotes: 2

Related Questions