android开发之给LinearLayout增加点击效果
2016-01-08 22:58
561 查看
场景: 给LinearLayout设置android:background="@drawable/ll_customer_selector",却没有效果
解决办法:给LinearLayout增加android:clickable="true"属性,是它可点击
示例代码如下:
在布局中xxx.xml中
解决办法:给LinearLayout增加android:clickable="true"属性,是它可点击
示例代码如下:
在布局中xxx.xml中
<LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/ll_customer_selector" android:clickable="true" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="收藏" android:textSize="12sp" /> </LinearLayout>在drawable下的ll_customer_selector.xml中
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ll_customer_selected" android:state_pressed="true"/> <!-- focused state --> <item android:drawable="@drawable/ll_customer_selected" android:state_focused="true"/> <!-- default state --> <item android:drawable="@drawable/ll_customer_normal"/> </selector>在drawable下的ll_customer_normal中
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ffffff" /> </shape>在drawable下的ll_customer_selected中
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#DCDCDC" /> </shape>
相关文章推荐
- (六)Android中Service通信
- 如何分析Android的Log
- Android设置监听回调的方式
- Android项目里,strings文件中字符串的格式化用法
- [Android]构建boot.img(三):boot.img的生成与结构
- [Android]构建boot.img(一):root目录与ramdisk.img的生成
- android132 360 05 手机定位
- android studio单元测试
- 【Android Studio】常用快捷键
- Android图片处理
- 【Android Studio】Gradle DSL method not found:'android()'
- Android SearchView设置与用法的那点事儿
- Android 的生命周期知识点问答
- 让多个fragment切换时不被实例化 android
- android 返回键的捕获
- Android Studio日志工具的使用
- 我在Ubuntu上安装Android Studio的全过程
- unregisterReceiver报错处理 android
- android基本控件学习-----ToggleButton&Switch
- Android Studio 1.5 正确导入so文件的方法