Android中背景选择器

来源:互联网 发布:淘宝9.9包邮专区在哪 编辑:程序博客网 时间:2024/05/16 01:41

相关属性

android:state_selected     选中未选中状态

android:state_pressed      点击未点击

android:state_focused      是否获得焦点

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


<selectorxmlns:android="http://schemas.android.com/apk/res/android">

    <itemandroid:state_enabled="false"android:drawable="@color/item_bg_textcolor"/>

    <itemandroid:state_enabled="true"android:drawable="@color/red"/>

</selector>


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

tagsGridV.setOnItemClickListener(new OnItemClickListener() {


@Override

publicvoid 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());

}

});



0 0
原创粉丝点击