Android - drawable with rounded corners at the top only

Aleks G

I had this drawable to have a rounded rectangle as a background:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white" />
    <stroke android:width="1dp" android:color="@color/light_gray" />
    <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
    <corners android:radius="6dp" />
</shape>

This is working fine, as expected.

Now, I want to change this to only round the top corners, so I change it to this:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white" />
    <stroke android:width="1dp" android:color="@color/light_gray" />
    <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
    <corners android:topLeftRadius="6dp" android:topRightRadius="6dp"
             android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
</shape>

But now none of the corners are rounded and I get a plain rectangle. What am I missing here?

aqs

Try giving these values:

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

Note that I have changed 0dp to 0.1dp.

EDIT: See Aleks G comment below for a cleaner version

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android: how to clip only top rounded corners

ImageView with only bottom or top corners rounded

NativeScript: WebView with rounded corners (Android Only)

Top rounded gradient drawable

How to create a layout with rounded corners on only the top or bottom half?

Only rounded bottom corners?

Transparent Activity With Top Rounded Corners

Buttons with rounded corners in android

Android Spannablecontent With Rounded Corners

Rounded corners for TABS in android

Android: Rounded corners in Menu

Android: Is there a simple way to create rounded corners for a view without having to create a separate drawable each time?

Android CardView with rounded corners displays grey corners

Rounded Corners and Borders in Android Studio

Android NavigationView vith rounded corners

Android Image Background with Rounded Corners

Android: give a webview rounded corners?

android custom searchView rounded corners

Android ImageView with rounded corners (again)

jQuery Mobile remove top rounded corners

Top Bar with rounded corners in Ubuntu 19.10

Create triangle with rounded corners at top of bottomsheet

Get top rounded corners on Flutter's DraggableScrollableSheet

android rounded rectangle drawable question

Can't get rounded corners for my layer-list drawable

Android: how to programmatically round only top corners of a bitmap?

Android round a Layouts background image, only top or bottom corners

Animate UIBezierPath from all rounded corners to path with top left and top right rounded corners

Rounded corners on rectangular image using CSS only