Adding a color background and border radius to a Layout

I want to create a layout with rounded corners and a filled color background.

This is my layout:

  • Android 1.6: “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”
  • Bluetooth connection issues with IntentService
  • HttpPost failed due to “Cannot retry request with a non-repeatable request entity”
  • Android development: Visual Studio + Java. Is it possible (worth a try)?
  • Android Background Image in XML File
  • Android OpenGL ES 2.0 screen coordinates to world coordinates
  • <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="210dp"
        android:orientation="vertical"
        android:layout_marginBottom="10dp"        
        android:background="@drawable/offerItemLayout">
        <LinearLayout
            android:id="@+id/offerImageHolder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
                .
                .
                .
        </LinearLayout>
    </LinearLayout>
    

    I have the following drawable xml (offerItemLayout) that creates the borders correctly:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                   android:shape="rectangle">
                <corners
                    android:radius="5dp"/>
                <stroke
                    android:width="1dp"
                    android:color="@color/bggrey" />            
            </shape>
        </item>
        // The lines below causes an inflation failure.
        <item>
            <fill
                android:color="@color/white"/>
        </item>
    </layer-list>
    

    But inserting the item with a fill causes the inflation of the layout to fail.

    Additionally, if I assign a color background to my inner LinearLayout (offerImageHolder), it overrides the first background with my rounded corners.

    Any thoughts on doing this properly? :/

    Related posts:

    encoding/decoding of data between php/java for android
    Keeping Android development separate from private account
    Facebook invite in phonegap returns OK
    &ldquo;No resource identifier found for attribute &#039;showAsAction&#039; in package &a...
    Android Lint - How to hide a warning &#039;The resource Xxx appears to be unused&#039;
    High CPU usage with Android emulator (qemu-system-i386.exe)
  • How to close/cancel/dismiss a System Dialog programmatically (Android)
  • Change actionbar color programmatically more than once
  • How can I put a view on top of a glSurfaceView with a transparent background?
  • Android ChatHead is limiting the touch to itself only, BUT I need support second finger simultaenously second touching the area outside the chathead,
  • Android: how to install apk on device, without using android sdk tools
  • Android Studio “Open Declaration” like eclipse
  • 2 Solutions collect form web for “Adding a color background and border radius to a Layout”

    You don’t need the separate fill item. In fact, it’s invalid. You just have to add a solid block to the shape. The subsequent stroke draws on top of the solid:

    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle">
    
        <corners android:radius="5dp" />
        <solid android:color="@android:color/white" />
        <stroke
            android:width="1dip"
            android:color="@color/bggrey" />
    </shape>
    

    You also don’t need the layer-list if you only have one shape.

    background.xml in drawable folder.

    <?xml version="1.0" encoding="UTF-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/>    
    <stroke android:width="3dp"
            android:color="#0FECFF" />
    <gradient                           //specify graident
        android:startColor="#ffffffff" 
        android:endColor="#110000FF" 
        android:angle="90"/> 
    
    <padding android:left="5dp"
             android:top="5dp"
             android:right="5dp"
             android:bottom="5dp"/> 
    <corners android:bottomRightRadius="7dp"
             android:bottomLeftRadius="7dp" 
             android:topLeftRadius="7dp"
             android:topRightRadius="7dp"/> 
    </shape>
    
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="210dp"
    android:orientation="vertical"
    android:layout_marginBottom="10dp"        
    android:background="@drawable/background">
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.