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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

nosxcy   2021-03-20 我要评论
想了解Android布局之LinearLayout自定义高亮背景的方法的相关内容吗,nosxcy在本文为您仔细讲解Android LinearLayout自定义高亮背景的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,LinearLayout,自定义,高亮背景,Android布局,下面大家一起来学习吧。

本文实例讲述了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程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们