How to make a shape with left-top round rounded corner and left-bottom rounded corner?

AndroidAndroid Shape

Android Problem Overview


I want to make a shape with with left-top rounded corner and left-bottom rounded corner:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#555555"/>    

    <stroke android:width="3dp"
            android:color="#555555"
            />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"
             /> 

    <corners android:bottomRightRadius="0dp" android:bottomLeftRadius="2dp" 
     android:topLeftRadius="2dp" android:topRightRadius="0dp"/> 
</shape>

But the shape above didn't give me what I want. It gives me a rectangle without any rounded corners.

Android Solutions


Solution 1 - Android

It looks like a bug http://code.google.com/p/android/issues/detail?id=939.

Finally I have to write something like this:

http://schemas.android.com/apk/res/android">

 <stroke android:width="3dp"
         android:color="#555555"
         />

 <padding android:left="1dp"
          android:top="1dp"
          android:right="1dp"
          android:bottom="1dp"
          /> 

 <corners android:radius="1dp"
  android:bottomRightRadius="2dp" android:bottomLeftRadius="0dp" 
  android:topLeftRadius="2dp" android:topRightRadius="0dp"/> 

I have to specify android:bottomRightRadius="2dp" for left-bottom rounded corner (another bug here).

Solution 2 - Android

While this question has been answered already (it's a bug that causes bottomLeftRadius and bottomRightRadius to be reversed), the bug has been fixed in android 3.1 (api level 12 - tested on the emulator).

So to make sure your drawables look correct on all platforms, you should put "corrected" versions of the drawables (i.e. where bottom left/right radii are actually correct in the xml) in the res/drawable-v12 folder of your app. This way all devices using an android version >= 12 will use the correct drawable files, while devices using older versions of android will use the "workaround" drawables that are located in the res/drawables folder.

Solution 3 - Android

From the documentation:

> NOTE: Every corner must (initially) be provided a corner radius greater than 1, or else no corners are rounded. If you want specific > corners to not be rounded, a work-around is to use android:radius to > set a default corner radius greater than 1, but then override each and > every corner with the values you really want, providing zero ("0dp") > where you don't want rounded corners.

E.g. you have to set an android:radius="<bigger than 1dp>" to be able to do what you want:

<corners 
    android:radius="2dp"
    android:bottomRightRadius="0dp" 
    android:topRightRadius="0dp"/> 

Solution 4 - Android

You can also use extremely small numbers for your radius'.

<corners 
  android:bottomRightRadius="0.1dp" android:bottomLeftRadius="2dp" 
 android:topLeftRadius="2dp" android:topRightRadius="0.1dp" />

Solution 5 - Android

for others there are a solution for any API level , you can place a item on top of each other example :

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

<!-- my firt item with 4 corners radius(8dp)
 -->
    <item>
        <shape>
            <solid
                android:angle="270.0"
                android:color="#3D689A" />

            <corners android:topLeftRadius="8dp" />
        </shape>
    </item>
<!-- my second item is on top right for a fake corner radius(0dp)
 -->
    <item
        android:bottom="30dp"
        android:left="50dp">
        <shape>
            <solid android:color="#5C83AF" />
        </shape>
    </item>
<!-- my third item is on bottom left for a fake corner radius(0dp)
 -->
    <item
        android:right="50dp"
        android:top="30dp">
        <shape>
            <solid android:color="#5C83AF" />
        </shape>
    </item>

</layer-list>

the result with light color to show you the three items :

enter image description here

the final result :

enter image description here

Best regards.

Solution 6 - Android

This bug is filed here. This is a bug of android devices having API level less than 12. You've to put correct versions of your layouts in drawable-v12 folder which will be used for API level 12 or higher. And an erroneous version(corners switched/reversed) of the same layout will be put in the default drawable folder which will be used by the devices having API level less than 12.

For example: I had to design a button with rounded corner at bottom-right.

In 'drawable' folder - button.xml: I had to make bottom-left corner rounded.

<shape>
    <corners android:bottomLeftRadius="15dp"/>
</shape>

In 'drawable-v12' folder - button.xml: Correct version of the layout was placed here to be used for API level 12 or higher.

<shape>
    <corners android:bottomLeftRadius="15dp"/>
</shape>

Solution 7 - Android

try this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/upkia"/>
<corners android:radius="10dp"
    android:topRightRadius="0dp"
    android:bottomRightRadius="0dp" />
</shape>

Solution 8 - Android

This works for me

  <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorPrimary" />
    <corners
        android:bottomLeftRadius="0dp"
        android:radius="@dimen/dimen_5dp"
        android:topLeftRadius="0dp" />
</shape>

Achived this

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser256239View Question on Stackoverflow
Solution 1 - Androiduser256239View Answer on Stackoverflow
Solution 2 - AndroidGeoffView Answer on Stackoverflow
Solution 3 - AndroidEntrecoView Answer on Stackoverflow
Solution 4 - AndroidMoncaderView Answer on Stackoverflow
Solution 5 - AndroidJamesView Answer on Stackoverflow
Solution 6 - AndroidReaz MurshedView Answer on Stackoverflow
Solution 7 - Androidsaigopi.meView Answer on Stackoverflow
Solution 8 - AndroidAalishan AnsariView Answer on Stackoverflow