您的位置:首页 > 移动开发 > Android开发

Android中背景选择器

2015-07-09 17:36 639 查看
相关属性

android:state_selected     选中未选中状态

android:state_pressed      点击未点击

android:state_focused      是否获得焦点

android:state_enabled      是否响应事件,包括所有事件

<selector
xmlns:android="http://schemas.android.com/apk/res/android">
    <item
android:state_enabled="false"
android:drawable="@color/item_bg_textcolor"/>
    <item
android:state_enabled="true"
android:drawable="@color/red"/>
</selector>

我这里写了一个例子,选择某个textview的时候背景颜色改变,再次点击恢复,点击保存的时候将选中的几个内容传回前一个界面

tagsGridV.setOnItemClickListener(new OnItemClickListener() {

@Override
public
void onItemClick(AdapterView<?> parent, View view,
int position,
long id) {
//1   当点击每一项时 如果已经被选中 也就是说isSelect为true 就把这一项的isSelsct设置成false 相反 false的时候变成true
tagList.get(position).setSelected(!tagList.get(position).isSelected());
TextView tagTextV = (TextView) view.findViewById(R.id.specific_text);
//2   根据list集合中被点击的对象中的isSelect设置enale状态
if(tagList.get(position).isSelected() ==
true){
tagTextV.setTextColor(getResources().getColor(R.color.white));
}else{
tagTextV.setTextColor(getResources().getColor(R.color.black));

}
tagTextV.setEnabled(tagList.get(position).isSelected());
}

});













内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 背景选择器