Ashutosh Bansal
Ashutosh Bansal

Reputation: 397

How to round the corner of one side of textview in android

I want to round the only one side of text-view like round from top left and one round from top right round and I use this code. But it not work.

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

<solid android:color="@color/login_layout" />

<stroke
        android:width="1dp"
        android:color="@color/login_layout" />

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

<corners
        android:bottomLeftRadius="0dip"
        android:bottomRightRadius="0dip"
        android:topLeftRadius="10dip"
        android:topRightRadius="10dip" />

</shape>

Upvotes: 16

Views: 15405

Answers (5)

Zeeshan Mirza
Zeeshan Mirza

Reputation: 4589

The simplest solution is to make an image with round corner and set it as background of the textView.

Upvotes: 2

C--
C--

Reputation: 16558

Change,

<corners
    android:bottomLeftRadius="0dip"
    android:bottomRightRadius="0dip"
    android:topLeftRadius="10dip"
    android:topRightRadius="10dip" />

to

<corners
    android:radius="5dip"
    android:bottomLeftRadius="0dip"
    android:bottomRightRadius="0dip"
    android:topLeftRadius="10dip"
    android:topRightRadius="10dip" />

Actually this is a bug in android and you have to manually set the radius attribute to some random value explicitly before applying other radius values.

Upvotes: 5

Dhruvil Patel
Dhruvil Patel

Reputation: 2930

make one xml in drawable folder.. suppose round.xml . Then edit it as below..

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

        android:color="#ffffff"
        />
    <corners 
        android:topLeftRadius="15px" 
        android:bottomLeftRadius="15px"
        />

     <padding
     android:top="3dp"
     android:bottom="3dp"
     />
</shape>

Then in background of textview set this xml.

Upvotes: 1

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

Please Try this way..

texttextshape.xml file.

<?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:bottomLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp"
         />

</shape>

and Set Text_view android:background="@drawable/texttextshape"

I think it help you..

Upvotes: 8

Syn3sthete
Syn3sthete

Reputation: 4171

sometimes It wont show in emulator and graphical layout try to run the code in a real device and check

Upvotes: 8

Related Questions