Подтвердить что ты не робот

Как установить форму фона в XML?

Я только что создал красный круг, используя андроидные фигуры:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadiusRatio="4"
    android:shape="ring"
    android:thicknessRatio="9"
    android:useLevel="false" >

     <solid android:color="#FF0000" />

    <size
        android:height="48dip"
        android:width="48dip" />

</shape>

Это действительно здорово, но я не могу установить цвет фона круга в свой цвет. Я попробовал android:background="#FFFFFF", но он всегда выглядит черным в моем макете. Как установить фон указанной выше формы?

4b9b3361

Ответ 1

Я думаю, что layer-list может вам помочь:

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

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#ffffff" />
        </shape>
    </item>
    <item>
        <shape
            android:innerRadiusRatio="4"
            android:shape="ring"
            android:thicknessRatio="9"
            android:useLevel="false" >
            <solid android:color="#FF0000" />
            <size
                android:height="48dip"
                android:width="48dip" />
        </shape>
    </item>

</layer-list>

Ответ 2

Хорошо, как насчет этого?

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:background="#FFFFFF">
<TextView android:text="Foo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:gravity="center"
    android:background="@drawable/red_circle"/>
    </LinearLayout>


</LinearLayout>

Ответ 3

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

    <corners android:radius="12dp" />
    <solid android:color="#ffffff" />
    <stroke
        android:width="1dp"
        android:color="@android:color/black" />

</shape>