I want to make a button exactly like in this image
I want to use a xml file that will us
I haven't tried all of the answers here, but I believe some/all of them are works.
The accepted answer is also works, but it can be simplified. Since I love elegant and simple solution, I come up with my own solution. Basically, we just need to add radius big enough compared with your View
width and height, so it will create a round corner. In this case I put 1000dp
to make it safe. We don't even need to add android:shape="rectangle"
at all.
Just follow these 2 simple steps:
Create an XML file in your drawable folder. For example let's name it bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="1000dp"/>
<solid android:color="@color/yourPreferredColor"/>
</shape>
Then you can use it in layout XML file as your View
property android:background="@drawable/bg"
or directly in the code view.setBackgroundResource(R.drawable.bg)