Original source: http://blog.csdn.net/nmsoftklb/article/details/9087233
A, in the development of everyone will encounter this situation, in a xxx.xml file if more than two components have the same attribute function, you can extract their common content
Put in the Styles.xml file to declare.
It can then be referenced in the corresponding component: style= "@style/widget_listview"
The style tag can also be defined like this: res-----values------styles.xml
<style name="widget_listview">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
/span>< item name = "Android:listselector" > @drawable / listview_item_selector </ item >
<item name="android:divider">@drawable/listview_divider_line</item>
<item name="android:dividerHeight">1.0dip</item>
<item name="android:fadingEdge">none</item>
<item name="android:scrollingCache">false</item>
</style>
b, in a layout if there is a set of buttons to change the color when the corresponding is selected (this group of buttons is not an array), this can be defined as follows: Add a Selector_btn.xml file under the drawable file
<?xml version="1.0" encoding="utf-8"?>
< selector xmlns : android = "http://schemas.android.com/apk/res/android"
/span>< item android : state_enabled = "true" Android : drawable = "@drawable/frame_button_n" ></ item > <!-- under normal circumstances -->
/span>< item android : state_enabled = "false" Android : drawable = "@drawable/frame_button_p" ></ item > <!-- button changes when pressed -->
</selector>
In the reference can be directly used android:background= "@drawable/selector_btn", note the red part of the property, can not be written state_pressed this property, in order to prevent the interface repeatedly click button Events, So when you click the button, you can pass in
articleManager.setOnClickListener(frameArticleBtnClick(articleManager, 1));
/**
* @param btn
* @param flag
* 记录哪个按钮被选中
* @return 当按下相应的按钮时颜色发生变化,并且该按钮处于不可重复点击状态
*/
Span class= "KWD" >private onclicklistener Framearticlebtnclick ( final button btn final int flag ) {
return new OnClickListener() {
@Override
public void onClick(View v) {
if (btn == articleManager) {
articleManager.setEnabled(false);
} else
articleManager.setEnabled(true);
if (btn == articleTypeManager) {
articleTypeManager.setEnabled(false);
} else
articleTypeManager.setEnabled(true);
currentFlagBtn = flag;
}
};
}
From for notes (Wiz)
Change the color of the button when pressed in Android