Search code examples
androidxmlandroid-layoutandroid-shapeandroid-shapedrawable

How can i achieve this custom Shape in android for a textview?


How would I achieve a shape like below in Android, through an Android shape drawable:

enter image description here


Solution

  • You can simply create a custom shape and set it as background to your TextView:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    
        <solid android:color="#00ff00" />
    
        <corners
            android:bottomRightRadius="4dp"
            android:topLeftRadius="4dp" />
    
    </shape>
    

    You can acchieve the shadow by just setting the elevation attribute on your TextView (or wrap it in a CardView and set the elevation tehre if you are using an older version of Android)