Android Button及TextView动态变换颜色
来源:互联网 发布:协同过滤算法matlab 编辑:程序博客网 时间:2024/05/16 06:43
做android应用程序,为了达到更好的用户交互效果,经常需要改变Button的背景颜色以及TextView的字体颜色来提示用户当前的菜单可操作的状态,对此android提供了一种定义一种selector的方法让程序员提前配置好背景和色值,具体的方法如下:
一.Button(ImageButton、ImageView包括一般的view、ViewGroup都可以同样操作):
1.首先在你的layout文件中为Button添加background属性,比如android:background="@drawable/btn_background"
2.在drawable目录下添加新的xml文件btn_background.xml,也就是定义一些selector标签,并指定Button在各种状态下背景图片,如下代码:
3.将上述xml文件中用到的图片放到drawable下就OK了。
二.TextView改变字体颜色:和Button的区别是改变的是textColor属性,而且selector文件定义在color目录下:
1.在layout文件中指定TextView的textColor属性,如android:textColor="@color/textview_color";
2.在color目录下添加新的xml文件textview_color.xml并指定TextView在各种状态下的色值,如下代码:
3. OK.
- Android Button及TextView动态变换颜色
- Android Button及TextView动态变换颜色
- Android Button及TextView动态变换颜色
- Android Button及TextView动态变换颜色
- Android Button及TextView动态变换颜色
- Android Button按钮点击变换字体颜色
- android listview中textview的颜色变换
- Android 代码里动态设置TextView/Button等的文字颜色Seletor
- Button点击颜色变换
- android的button点击变换颜色的方法
- Android动态改变TextView字体颜色
- Android动态改变TextView字体颜色
- android动态改变textView字体的颜色
- Android中动态设置TextView的颜色
- Android中动态设置TextView的颜色
- Android 动态修改TextView 颜色Color
- 【Android---项目中】TextView动态设置颜色
- Android之TextView动态设置颜色
- 『babyt』SD2C2008杂记之非技术部分之第一天
- TSE(Tiny Search Engine)介绍
- ResultSet详解
- Request获取页面传值
- 出来了,下载吧。《红帽Linux6.0 服务器版》(Red Hat Enterprise Linux Server 6.0)官方多国语言版
- Android Button及TextView动态变换颜色
- WebGoat学习笔记(四)——Phishing with XSS
- MAC学习资源推荐
- [自问自答]Android开发 如何在虚拟机上模拟sim卡?
- rt
- 苹果笔记本,电源指示灯一直为橙色的解决办法
- switch等值比较的写法改进
- C#操作Excel
- 『babyt』SD2C2008杂记之非技术部分之第二天