开发中需要对EditText样式进行特殊化定义,使用selector进行获取焦点和失去焦点的样式设计:
代码实现:
searchText.setBackgroundResource(R.drawable.search_edit_selector);
所有的样式和selector都放在drawable目录;
edit_selector.xml书写方式:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/search_edittext_style" android:state_window_focused="false"/>
<item android:drawable="@drawable/search_edittext_style_focused" android:state_focused="true"/>
</selector>
search_edittext_style.xml样式书写,使用layer-list 实现:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android&