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: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());
}
});
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories