Android beautifying EditText and androidedittext
Currently, all apps focus on user experience. Here we will introduce the styles and beautification of the EditText control.
First:
Note:The first control does not have any properties for background. The second control sets android: background = "@ drawable/bg_edittext_selector"
To cancel the EditText background, set android: background = "@ null.
Here, we use two xml files to set the styles that do not obtain the focus and that have already obtained the focus, which are implemented through the shape.
Edittext_focused.xml
<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF" /> <corners android:radius="1dip"/> <stroke android:width="1dip" android:color="#728ea3" /></shape>
Edittext_normal.xml
<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF" /> <corners android:radius="1dip"/> <stroke android:width="1dip" android:color="#BDC7D8" /></shape>
Note:Here, you can set the corners (angle) to set the Radian of the border. For more information about shape attributes, see.
Bg_edittext_selector.xml
<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/edittext_normal" android:state_window_focused="false"/> <item android:drawable="@drawable/edittext_focused" android:state_focused="true"/></selector>
Activity_main.xml
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" tools: context = "com. example. aa. mainActivity "> <EditText android: id =" @ + id/normal "android: layout_width =" fill_parent "android: layout_height =" 36dip "android: layout_margin =" 36dip "android: hint = "Enter the user name" android: padding = "5dip" android: singleLine = "true" android: textColorHint = "# AAAAAA" android: textSize = "15dip"/> <EditText android: layout_below = "@ + id/normal" android: layout_width = "fill_parent" android: layout_height = "36dip" android: layout_margin = "36dip" android: background = "@ drawable/bg_edittext_selector" android: hint = "Enter the user name" android: padding = "5dip" android: singleLine = "true" android: textColorHint = "# AAAAAA" android: textSize = "15dip"/> </RelativeLayout>