Android布局之LinearLayout自定义高亮背景的方法
作者:nosxcy 时间:2022-07-05 09:48:10
本文实例讲述了Android布局之LinearLayout自定义高亮背景的方法。分享给大家供大家参考,具体如下:
首先创建linearlayout_background.xml文件
res/drawable/linearlayout_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<itemandroid:state_pressed="true" android:drawable="@drawable/button_pressed"/>
<itemandroid:state_focused="true" android:drawable="@drawable/button_pressed"/>
<itemandroid:drawable="@drawable/button_normal"/>
</selector>
其次在对应的xml布局文件中
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="true"<!--这条是必须的,否则没有高亮显示效果,这有别于自动的button,textview等其他控件-->
android:background="@drawable/linearlayout_background">
<Button ....../>
<TextView ...../>
</LinearLayout>
希望本文所述对大家Android程序设计有所帮助。
标签:Android,LinearLayout
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现Base64加密解密算法
2023-11-25 08:07:27
C#数据结构与算法揭秘二 线性结构
2023-02-10 00:30:46
![](https://img.aspxhome.com/file/2023/7/98217_0s.png)
关于springboot集成swagger及knife4j的增强问题
2023-11-29 00:43:50
![](https://img.aspxhome.com/file/2023/1/60271_0s.png)
MyBatis常用的jdbcType数据类型
2023-09-18 19:09:35
快速入门介绍Java中强大的String.format()
2022-10-28 15:53:49
.net实现裁剪网站上传图片的方法
2021-09-24 01:41:05
C#去除字符串中的反斜杠实例(推荐)
2022-02-02 20:27:14
![](https://img.aspxhome.com/file/2023/3/119513_0s.jpg)
Unity实现物体左右移动效果
2021-12-17 15:52:31
![](https://img.aspxhome.com/file/2023/0/119500_0s.gif)
SpringSecurity解决POST方式下CSRF问题
2023-07-18 18:59:51
springboot使用log4j2异步日志提升性能的实现方式
2021-05-31 16:54:55
![](https://img.aspxhome.com/file/2023/8/72658_0s.png)
解析Tars-Java客户端源码
2023-04-08 01:18:39
![](https://img.aspxhome.com/file/2023/7/89587_0s.jpg)
Kotlin伴随对象的初始化方法示例讲解
2022-07-24 05:53:06
C#根据日期计算星期几的实例代码
2021-07-24 21:43:34
Struts2实现文件上传功能实例解析
2023-11-04 04:56:13
![](https://img.aspxhome.com/file/2023/6/58836_0s.png)
详解如何为SpringBoot项目中的自定义配置添加IDE支持
2021-10-07 05:51:01
![](https://img.aspxhome.com/file/2023/5/104205_0s.png)
C#实现将汉字转化为2位大写的16进制Unicode的方法
2022-03-11 21:45:07
Spring Boot 结合 aop 实现读写分离
2023-09-29 07:53:02
![](https://img.aspxhome.com/file/2023/6/62526_0s.png)
C#/VB.NET实现在Word文档中添加页眉和页脚
2022-02-09 07:57:46
![](https://img.aspxhome.com/file/2023/3/92983_0s.jpg)
Java 添加、替换、删除PDF中的图片的示例代码
2023-08-28 09:06:26
![](https://img.aspxhome.com/file/2023/7/71637_0s.jpg)
mybatis的插件机制示例详解
2023-02-24 23:46:17