Demo2\aa\src\main\res\drawable\bg_border.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Shapexmlns:android= "Http://schemas.android.com/apk/res/android">3 <!--set the background color to transparent -4 <SolidAndroid:color= "#0000"/>5 <!--Set red Border -6 <StrokeAndroid:width= "4DP"Android:color= "#f00"/>7 </Shape>
Demo2\aa\src\main\res\drawable\bg_border2.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Shapexmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:shape= "Rectangle">4 <!--specifies the radius of the 4 rounded corners of a rounded rectangle -5 <Corners6 Android:bottomleftradius= "5DP"7 Android:bottomrightradius= "20DP"8 Android:topleftradius= "20DP"9 Android:toprightradius= "5DP" />Ten <!--Specify the width and color of the border line - One <Stroke A Android:width= "4DP" - Android:color= "#f0f" /> - <!--Specifies to use a gradient background color, using a gradient of type sweep (red-green-blue) - the <Gradient - Android:centercolor= "#0f0" - Android:endcolor= "#00f" - Android:startcolor= "#f00" + Android:type= "Sweep" /> - </Shape>
Demo2\aa\src\main\res\layout\activity_main.xml
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical"6 Tools:context=". Mainactivity ">7 8 <!--specifying a background by background -9 <TextViewTen Android:layout_width= "Match_parent" One Android:layout_height= "Wrap_content" A Android:text= "Text with borders" - android:textsize= "24SP" - Android:background= "@drawable/bg_border"/> the <TextView - Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - Android:text= "rounded border, text of gradient background" + android:textsize= "24SP" - Android:background= "@drawable/bg_border2"/> + A </LinearLayout>
Rounded borders and gradients