android开发之给LinearLayout增加点击效果
16lz
2022-03-06
场景:给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>
更多相关文章
- Android(安卓)webkit image的加载过程解析(三)
- Android(安卓)动画效果 --Animation 动画专题研究
- 学习Android从0开始之基础篇(3)-视图组件之布局管理器
- Android的CheckBox控件的点击效果布局文件
- android自定义滚动条(ScrollBar)样式
- Android(安卓)XML属性在文档中的位置
- Android(安卓)界面布局
- Android(安卓)Property Animation动画
- Android(安卓)Framework 修改设备连接电脑时的显示名称