Add a red border:
XML for TextView:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" android:paddingleft= "20DP" android:paddingright= "20DP" > <!-- Specify background by Android:background-- <textview android:layout_width= "match_parent" android:layout_ height= "Wrap_content" android:text= "text with border" android:textsize= "24sp" android:background= "@ Drawable/bg_border " /></linearlayout>
Border xml: (new Folder drawable. Then create a new file under this folder Bg_border.xml)
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--set red border--><stroke android:width= "2DP" android:color= "#f00"/></shape>
Effect
Gradient color:
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android:shape= "Rectangle" > <!--Specify the radius of 4 fillets of rounded rectangles--<corners android:topleftradius= "5DP" android: toprightradius= "5DP" android:bottomleftradius= "5DP" android:bottomrightradius= "5DP" /> <!-- Specifies the width and color of the border line--<stroke android:width= "4DP" android:color= "#f0f"/> <!--Specifies to use a gradient background color, using the sweep type of gradient, Color from red to green to blue--<gradient android:startcolor= "#f00" android:centercolor= "#0f0" android:endcolor= "# 00f " android:angle=" android:centerx= " 0.5" android:centery= "0.5" /></shape>
Effect:
Description
(1) Shape node configuration is the form of graphics, mainly including square, round and so on
(2) Gradient node main configuration start color, end color and middle point color, coordinates, gradient effect (0,90,180 from left to right gradient, 270 from top to bottom gradient) default from left to right.
(3) The radius of the corners node is configured around the rounded corners.
Android rounded border, gradient background TextView