Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

Rounded corner for textview in android

I have a textview and want its corner to be in round shape. I already know it can be done using android:background="@drawable/somefile". In my case, this tag is already included so cannot use again. e.g android:background="@drawable/mydialogbox" is already there to create image in background

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="top"
    android:background="@drawable/mydialogbox"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textview_name"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    </LinearLayout>

</RelativeLayout>

so when I want textview(textview_name) also with round corner, how this can be achieved.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Create rounded_corner.xml in the drawable folder and add the following content,

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >         
       <stroke
           android:width="1dp"
           android:color="@color/common_border_color" />
    
       <solid android:color="#ffffff" />
    
       <padding
            android:left="1dp"
            android:right="1dp"
            android:bottom="1dp"
            android:top="1dp" />
    
       <corners android:radius="5dp" />
    </shape>
    
  2. Set this drawable in the TextView background property like so:

    android:background="@drawable/rounded_corner"
    

I hope this is useful for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...