码迷,mamicode.com
首页 > 移动开发 > 详细

android selector

时间:2014-08-25 16:48:04      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   java   使用   io   文件   

android 选择器的使用

1.在drawable文件夹下面建一个xml文件,如item.xml,在eclipse中有selector这个选项

2.可以在布局文件.xml(配置android:listSelector="@drawable/item")中或者,java代码中使用

Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg); 

ListView.setSelector(drawable);

效果是一样的

 

这里我用的是listview做实验,item.xml

1 <?xml version="1.0" encoding="utf-8"?>
2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
3     <item android:drawable="@drawable/one"/>
4 
5 </selector>

java代码(片段)

1 ListView listView = new ListView(this);
2         Drawable itemBackground = getResources().getDrawable(R.drawable.itembackground);
3         listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData()));
4         listView.setSelector(itemBackground);
5         setContentView(listView);

这里效果可以看到点击一个选项是背景图片会变换

 参考:http://www.2cto.com/kf/201110/107866.html

android selector

标签:android   style   blog   http   color   java   使用   io   文件   

原文地址:http://www.cnblogs.com/luckygxf/p/3935146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!