Reprint please indicate the source, thank you: http://blog.csdn.net/harryweasley/article/details/46906681
Notice in advance: This blog is based on the TV set-top box, all the operation is to use the remote control.
Look first, when selected, the EditText has a border.
If shown, when the UI wants us to do this, it's pretty easy to do it, change the background directly, and you can, as shown here:
Layout, edittext join background on it.
<edittext android:id= "@+id/edittext_search" android:layout_width= "@dimen/edit_text_width" android:layout_height= "46DP" android:layout_marginleft= "@dimen/search_grid_left" android:layout_ marginright= "@dimen/search_grid_left" android:layout_margintop= "@dimen/search_edittext_top" android: background= "@drawable/background_edittext_selector" android:paddingleft= "10DP" android:textcolor= "@ Color/white " android:textsize=" @dimen/text_detail_app_name "/>
Under Res/drawable, build the Background_edittext_selector.xml file as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_focused=" true " android:drawable=" @drawable/edittext_background "> </item></selector>
Under Res/drawable, the Edittext_background.xml file resembles the following:
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--interior colors-- <solid android:color= "@color/edittext_bg"/> <!--edge Line Color -- <stroke android:width= "3DP" android:color= "@color/selected_bg"/> <!--rounded corners-- < Corners android:radius= "0DP"/></shape>
This will make the effect.
But, however, the UI says, you do this out of the inner border, what I want is an outer border.
So how should this be done, or the above ideas. When the EditText has no focus, we give him the edge line width of 6DP, the color is not set, when EditText gets to the focus is, we give him the edge lines width is set to 3DP, and set the color. Haha, this will solve the problem.
<edittext android:id= "@+id/edittext_search" android:layout_width= "@dimen/edit_text_width" android:layout_height= "46DP" android:layout_marginleft= "@dimen/search_grid_left" android:layout_ marginright= "@dimen/search_grid_left" android:layout_margintop= "@dimen/search_edittext_top" android: background= "@drawable/background_edittext_selector" android:paddingleft= "10DP" android:textcolor= "@ Color/white " android:textsize=" @dimen/text_detail_app_name "/>
Here two drawable are set, the width and color are different.
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_focused=" true " android:drawable=" @drawable/selected_edittext_ Background "></item> <item android:drawable=" @drawable/edittext_background "></item ></selector>
Edittext_background The Edge line is 6DP and does not set the color when the focus is not taken.
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--interior colors-- <solid android:color= "@color/edittext_bg"/> <!--edge Line Color -- <stroke android:width= "6DP"/> <!--fillet amplitude and <corners android:radius= "0DP"/></shape >
Selected_edittext_background gets the focus, as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--interior colors-- <solid android:color= "@color/edittext_bg"/> <!--edge Line Color -- <stroke android:width= "3DP" android:color= "@color/selected_bg"/> <!--rounded corners-- < Corners android:radius= "0dp"/> </shape>
Look first, when selected, the EditText has a border.
If shown, when the UI wants us to do this, it's pretty easy to do it, change the background directly, and you can, as shown here:
Layout, edittext join background on it.
<edittext android:id= "@+id/edittext_search" android:layout_width= "@dimen/edit_text_width" android:layout_height= "46DP" android:layout_marginleft= "@dimen/search_grid_left" android:layout_ marginright= "@dimen/search_grid_left" android:layout_margintop= "@dimen/search_edittext_top" android: background= "@drawable/background_edittext_selector" android:paddingleft= "10DP" android:textcolor= "@ Color/white " android:textsize=" @dimen/text_detail_app_name "/>
Under Res/drawable, build the Background_edittext_selector.xml file as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_focused=" true " android:drawable=" @drawable/edittext_background "> </item></selector>
Under Res/drawable, the Edittext_background.xml file resembles the following:
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--interior colors-- <solid android:color= "@color/edittext_bg"/> <!--edge Line Color -- <stroke android:width= "3DP" android:color= "@color/selected_bg"/> <!--rounded corners-- < Corners android:radius= "0DP"/></shape>
This will make the effect.
But, however, the UI says, you do this out of the inner border, what I want is an outer border.
So how should this be done, or the above ideas. When the EditText has no focus, we give him the edge line width of 6DP, the color is not set, when EditText gets to the focus is, we give him the edge lines width is set to 3DP, and set the color. Haha, this will solve the problem.
<edittext android:id= "@+id/edittext_search" android:layout_width= "@dimen/edit_text_width" android:layout_height= "46DP" android:layout_marginleft= "@dimen/search_grid_left" android:layout_ marginright= "@dimen/search_grid_left" android:layout_margintop= "@dimen/search_edittext_top" android: background= "@drawable/background_edittext_selector" android:paddingleft= "10DP" android:textcolor= "@ Color/white " android:textsize=" @dimen/text_detail_app_name "/>
Here two drawable are set, the width and color are different.
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_focused=" true " android:drawable=" @drawable/selected_edittext_ Background "></item> <item android:drawable=" @drawable/edittext_background "></item ></selector>
Edittext_background The Edge line is 6DP and does not set the color when the focus is not taken.
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--interior colors-- <solid android:color= "@color/edittext_bg"/> <!--edge Line Color -- <stroke android:width= "6DP"/> <!--fillet amplitude and <corners android:radius= "0DP"/></shape >
Selected_edittext_background gets the focus, as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--interior colors-- <solid android:color= "@color/edittext_bg"/> <!--edge Line Color -- <stroke android:width= "3DP" android:color= "@color/selected_bg"/> <!--rounded corners-- < Corners android:radius= "0dp"/> </shape>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
What to do with the outer border of the control, not the inner frame