androidxmlandroid-studioandroid-drawableandroid-shapedrawable

Rounded Corners and Borders in Android Studio


I want to add rounded corners and borders to a textview. But only the top corners should be rounded and the bottom should be without border. Already found this:

https://www.android-examples.com/add-rounded-border-to-textview-programmatically/

But then I have rounded corners at the bottom too.

How can I change this?


Solution

  • Create a drawable file like this :

        <?xml version="1.0" encoding="utf-8"?>
    <inset xmlns:android="http://schemas.android.com/apk/res/android"
        android:insetBottom="-4dp">
    
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <stroke android:width="4dp" android:color="#000000" />
            <corners android:radius="4dp" />
        </shape>
    
    </inset>
    

    And then apply it as an background of any control and there you go, it's done.