Border and gradient, border gradient
Demo2 \ aa \ src \ main \ res \ drawable \ bg_border.xml
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <shape xmlns: android = "http://schemas.android.com/apk/res/android"> 3 <! -- Set the background color to transparent color --> 4 <solid android: color = "#0000"/> 5 <! -- Set the red border --> 6 <stroke android: 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 <shape xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: shape = "rectangle"> 4 <! -- Specify the radius of the four rounded corners of the rounded rectangle --> 5 <corners 6 android: bottomLeftRadius = "5dp" 7 android: bottomRightRadius = "20dp" 8 android: topLeftRadius = "20dp" 9 android: topRightRadius = "5dp"/> 10 <! -- Specify the border line width and color --> 11 <stroke12 android: width = "4dp" 13 android: color = "# f0f"/> 14 <! -- Specifies that the gradient background color is used, and the gradient of the sweep type is used (red, green, and blue) --> 15 <gradient16 android: centerColor = "#0f0" 17 android: endColor = "# 00f" 18 android: startColor = "# f00" 19 android: type = "sweep"/> 20 </shape>
Demo2 \ aa \ src \ main \ res \ layout \ activity_main.xml
1 <LinearLayout xmlns: 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 <! -- Specify the background through background --> 9 <TextView10 android: layout_width = "match_parent" 11 android: layout_height = "wrap_content" 12 android: text = "text with border" 13 android: textSize = "24sp" 14 android: background = "@ drawable/bg_border"/> 15 <TextView16 android: layout_width = "match_parent" 17 android: layout_height = "wrap_content" 18 android: text = "rounded border, gradient background text" 19 android: textSize = "24sp" 20 android: background = "@ drawable/bg_border2"/> 21 22 </LinearLayout>