场景:给LinearLayout设置android:background="@drawable/ll_customer_selector",却没有效果

解决办法:给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>






更多相关文章

  1. Android(安卓)webkit image的加载过程解析(三)
  2. Android(安卓)动画效果 --Animation 动画专题研究
  3. 学习Android从0开始之基础篇(3)-视图组件之布局管理器
  4. Android的CheckBox控件的点击效果布局文件
  5. android自定义滚动条(ScrollBar)样式
  6. Android(安卓)XML属性在文档中的位置
  7. Android(安卓)界面布局
  8. Android(安卓)Property Animation动画
  9. Android(安卓)Framework 修改设备连接电脑时的显示名称

随机推荐

  1. android中的两端对齐
  2. Android(安卓)获取通讯录信息
  3. 读取raw文件下文件内容
  4. android BadTokenException之token is no
  5. 2011.08.12(2)——— android MediaPlayer
  6. android-GooglePlay安装来源追踪PlayInst
  7. 在下方的tab页
  8. GoogleAndroid常用的Android常量
  9. Android(安卓)Media Framework 总纲
  10. android截屏代码:C++实现