Android中有用的Item选中和按下去的样式
来源:互联网 发布:java自动获取当前时间 编辑:程序博客网 时间:2024/05/16 11:15
Android比较好的一点就是可以方便的定义自己常用的样式,而且可以重复使用。
下面是hmg25朋友能的一个选中item和按下item时候的样式,个人感觉跟系统的ListView比较相似,
所以记一下备用。。。
下面先看运行结果:
下面是focus选中时候的样子
下面是点击按下去的样子:
把下面的内容保存为xml文件,并放入到drawable文件夹中:
dockbar_selector.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <selector
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_pressed="true" android:drawable="@drawable/selector_pressed_shape" />
- <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/selector_focused_shape" />
- <item android:state_focused="true" android:state_window_focused="false" android:drawable="@android:color/transparent" />
- </selector>
selector_focused_shape.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <shape
- xmlns:android="http://schemas.android.com/apk/res/android">
- <solid android:color="#ffff9000" />
- <stroke android:width="0.0dip" android:color="#00000000" />
- <padding android:left="0.0dip" android:top="0.0dip" android:right="0.0dip" android:bottom="0.0dip" />
- <corners android:topLeftRadius="6.0dip" android:topRightRadius="6.0dip" android:bottomLeftRadius="6.0dip" android:bottomRightRadius="6.0dip" />
- </shape>
selector_pressed_shape.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <shape
- xmlns:android="http://schemas.android.com/apk/res/android">
- <solid android:color="#ffffba00" />
- <stroke android:width="0.0dip" android:color="#00000000" />
- <padding android:left="0.0dip" android:top="0.0dip" android:right="0.0dip" android:bottom="0.0dip" />
- <corners android:topLeftRadius="6.0dip" android:topRightRadius="6.0dip" android:bottomLeftRadius="6.0dip" android:bottomRightRadius="6.0dip" />
- </shape>
然后调用的时候,只需在layout的xml文件里面加上背景属性即可:
- android:background="@drawable/dockbar_selector"
- Android中有用的Item选中和按下去的样式
- Android中有用的Item选中和按下去的样式
- Android中有用的Item选中和按下去的样式
- Android中有用的组件被选中和按下去的变换样式
- Android 保留listview item的选中样式
- Android初级教程_保留listview item的选中样式
- 改变navigation drawer中item被选中时的样式
- Android 选中Gridiew的item
- 如何模拟android 中GridView的选中item的事件
- android tabhost 每个item的选中改变背景,和标题
- android tabhost 每个item的选中改变背景,和标题
- 如何更改GridView的item按下去的背景?
- 如何更改GridView的item按下去的背景?
- 关于Android的ListView的Item选中
- iOS开中设置UITabBar的背景图片以及各个item的选中图片和未选中
- Android 自定义ListView格局和各Item的样式
- RecyclerView中item的选中效果
- 一些有用的Item
- java多线程
- Windows远程访问linux数据库
- Jquery学习笔记——自定义事件
- 无法使用前导 .. 在顶级目录上退出
- 基础不牢地动山摇啊~
- Android中有用的Item选中和按下去的样式
- JQUERY打造隐藏在左侧的弹性弹出菜单
- 工程师必要了解的网站
- 000015.OracleSQL执行计划
- setInterval用法注意
- Android逐条加载ListView,实现动画更新
- delphi读取xml文件
- linux内核GPIO模拟I2C实例
- 复制构造函数(copy constructor)