Tolgay Toklar
Tolgay Toklar

Reputation: 4343

Creating rounded view in android

I have to create this view in android:

enter image description here

But this is not a button. How can I create this view?

Upvotes: 0

Views: 156

Answers (3)

Akber
Akber

Reputation: 523

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

<solid android:color="#ffffff"/>
<corners android:radius="12dp" />// set your radius accordingly

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

</shape>

Make any desired layout and set this file(put it in the drawable folder) as background, here radius will be applied equally on each corner.

Upvotes: 1

Eric B.
Eric B.

Reputation: 4702

I assume this is a LinearLayout with 2 TextViews in it. You can create a custom background drawable in xml like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke android:color="YOUR ORANGE HEX COLOR" android:width="4dp"/>
<corners
    android:bottomRightRadius="25dp"
    android:bottomLeftRadius="25dp"
    android:topLeftRadius="25dp"
    android:topRightRadius="25dp"/>
</shape>

Adjust the storke width and the radius values as per your need.

Upvotes: 3

KishuDroid
KishuDroid

Reputation: 5451

Put this xml in drawable folder

Round.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:state_pressed="true" >
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#ffffff" />
         <gradient android:angle="-90" android:startColor="#ffffff" android:endColor="#ffffff"  />            
     </shape>
 </item>
<item android:state_focused="true">
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#ffffff" />
         <solid android:color="#ffffff"/>       
     </shape>
 </item>  
<item >
    <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#ffffff" />
         <gradient android:angle="-90" android:startColor="#ffffff" android:endColor="#ffffff" />            
     </shape>
 </item>
</selector>

And use it as background of anyview like view , button , imagebutton etc.

Upvotes: 0

Related Questions