round corners with border color
Asked Answered
T

2

27

I am using the following code to get rounded corners as well as a colored outline:

<?xml version="1.0" encoding="UTF-8"?> 

<gradient 
    android:startColor="@color/white" 
    android:endColor="@color/white" /> 

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

<stroke
    android:width="5dip"
    android:color="@color/black" />

round corners with border color

The image displays what I'm getting right now. Due to the stroke, the rounded corners only lie on the outer edge of the layout and the inner edge of the black outline makes a rectangle with sharp edges. How can I convert the sharp edges to rounded corners?

Thorncombe answered 6/11, 2012 at 15:48 Comment(0)
K
84

Use the <shape> tag to create a drawable in XML with rounded corners. (You can do other stuff with the shape tag like define a color gradient as well).

Following code may help you:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="#ffffffff"/>    

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

<padding android:left="1dp"
         android:top="1dp"
         android:right="1dp"
         android:bottom="1dp"
         /> 

<corners android:bottomRightRadius="7dp" 
         android:bottomLeftRadius="7dp" 
         android:topLeftRadius="7dp"
         android:topRightRadius="7dp"/> 
</shape>
Kowtow answered 6/11, 2012 at 15:52 Comment(2)
Thanks! Just to clatify, the border is given by the stroke tag.Firsthand
This also works well as the background for say EditText itemsBuilt
S
8

Use this customize according to your need.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <stroke
        android:width="4dp"
        android:color="@android:color/holo_blue_light" />
    <corners android:radius="6dp" />
</shape>
Speller answered 18/9, 2017 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.