服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android布局之LinearLayout自定义高亮背景的方法

Android布局之LinearLayout自定义高亮背景的方法

2021-05-13 14:05nosxcy Android

这篇文章主要介绍了Android布局之LinearLayout自定义高亮背景的方法,实例分析了Android中LinearLayout布局参数设置技巧,需要的朋友可以参考下

本文实例讲述了Android布局之LinearLayout自定义高亮背景的方法。分享给大家供大家参考,具体如下:

首先创建linearlayout_background.xml文件

res/drawable/linearlayout_background.xml

?
1
2
3
4
5
6
<?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布局文件中

?
1
2
3
4
5
6
7
8
<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程序设计有所帮助。

延伸 · 阅读

精彩推荐