点击LinearLayout动态改变其背景
来源:互联网 发布:通用软件无线电平台 编辑:程序博客网 时间:2024/05/26 16:01
也许大家用LinearLayout的时候会希望得到这样的效果:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/buttonbackgroundselected"/>
<item android:state_pressed="true" android:drawable="@drawable/buttonbackgroundselected"/>
<item android:state_focused="false" android:drawable="@drawable/buttonbackgroundnormal"/>
</selector>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/buttonbackground"
>
但是呢:
你这样做后,会发现,即使你用手触摸了LinearLayout,那么剩下的它也不会按照你所想的那样,动态的去改变背景的颜色,怎么解决呢?
解决方案其实非常的简单,直接添加属性:android:clickable="true"就行了
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/buttonbackgroundselected"/>
<item android:state_pressed="true" android:drawable="@drawable/buttonbackgroundselected"/>
<item android:state_focused="false" android:drawable="@drawable/buttonbackgroundnormal"/>
</selector>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/buttonbackground"
>
但是呢:
你这样做后,会发现,即使你用手触摸了LinearLayout,那么剩下的它也不会按照你所想的那样,动态的去改变背景的颜色,怎么解决呢?
解决方案其实非常的简单,直接添加属性:android:clickable="true"就行了
因为默认的LinearLayout是不能点击的,因此相关的事件便无法传递到LinearLayout,添加这个属性后,LinearLayout的背景便可以动态的进行变化了.
- 点击LinearLayout动态改变其背景
- 点击linearlayout,改变背景颜色
- 动态改变LinearLayout的背景
- android LinearLayout 单击动态改变背景
- android LinearLayout 单击动态改变背景
- 点击listview item 改变其背景
- 点击listview item 改变其背景
- Android开发技巧:点击Button改变其背景颜色
- 点击textview 使用selector改变对应viewGroup(LinearLayout,RelativeLayout)的背景
- 控件容器如何点击后改变背景颜色(如LinearLayout...)
- android gridview点击子选项动态改变item背景颜色
- 点击改变背景颜色
- Android—改变LinearLayout背景颜色
- DataGrid中以多列显示数据,并且对用户的点击改变其背景
- Android中在点击GridView的item时改变其背景
- 点击改变网页图片背景
- Android控件背景点击改变
- android 动态改变LinearLayout 宽高参数
- poj 1797 Heavy Transportation
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- c++下实现异形窗口(上方只显示文字其他区域穿透,下方半透明)
- 错误提示「URL file-access is disabled in the server configuration」解决方案
- php-cgi进程占用cpu资源过大原因分析及解决(找出有问题的linux进程)
- 点击LinearLayout动态改变其背景
- 工厂模式的理解
- Eclopse调试java方式详谈
- 数据库事务的隔离级别
- VM Ware 安装fedora 9 系统
- jsp面试收集
- Tracking-Learning-Detection TLD解析三 - Learning学习(跟踪与检测的协调与更新)
- java 反射
- RVMDK环境下STM32的链接过程