Android-shape is simple to use, Android-shape
Shape
Let's take a look at the built-in EditText and Button shapes.
The following figure shows the effect after adding a shape.
To put it simply, a shape can add a background border to the component, and a rounded corner can be used with selector.
ShapeXXX. xml is defined in the drawable directory.
The
<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Rectangle oval line ring --> <shape android: shape = "rectangle" xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Rounded corner of the four corners --> <corners android: radius = "5dp"/> <! -- Padding --> <padding android: bottom = "6dp" android: left = "5dp" android: right = "5dp" android: top = "6dp"/> <! -- Fill color to add as needed --> <solid android: color = "# FFFAE3"/> <! -- Border color needs to be added, --> <stroke android: color = "#87 CEFA" android: width = "1dp"/> </shape>
The buttons use the same definition.
<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Rectangle oval line ring --> <shape android: shape = "rectangle" xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Rounded corner of the four corners --> <corners android: radius = "8dp"/> <! -- Padding --> <padding android: bottom = "5dp" android: left = "3dp" android: right = "3dp" android: top = "5dp"/> <! -- Fill color --> <solid android: color = "# 09A3DC"/> <! -- Border color --> <stroke android: color = "#88000000" android: width = "1dp"/> </shape>
Use group in layout in the background attribute
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: orientation = "vertical" android: layout_width = "match_parent" android: layout_height = "match_parent"> <EditText android: layout_margin = "10dp" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: background = "@ drawable/shap_et" android: hint = "Enter the user name"/> <Button android: layout_margin = "10dp" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: textColor = "# ffffff" android: background = "@ drawable/shap_btn" android: text = "OK"/> </LinearLayout>