Simon
Simon

Reputation: 19948

Android: Changing background of a drawable

I have a rounded corner drawable background for the comment activity layout in my app (layout_bg_round_corners):

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/deep_orange"/>
    <corners android:radius="20dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

The background of the drawable shine through as white. Instead, I want them to be black.

How can I set the background color for a drawable?

comment

This is how I have set the parent view's layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/layout_bg_round_corners"

Upvotes: 0

Views: 580

Answers (3)

Sumit Pathak
Sumit Pathak

Reputation: 529

Hey you need to give black color to the relative layout, try this

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/layout_bg_round_corners">

Upvotes: 1

mjp66
mjp66

Reputation: 4213

Unless I've completely misunderstood you, layer-list drawable should do the trick :)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape>
            <solid android:color="#000000" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="@color/deep_orange"/>
            <corners android:radius="20dip"/>
            <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
        </shape>
    </item>

</layer-list>

Upvotes: 1

Will Evers
Will Evers

Reputation: 942

in the layout xml add the tag android:background="color code"

OR you can set the background to a drawable by replacing the color code with a drawable id.

Upvotes: 0

Related Questions