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


本文向大家介绍Android布局之LinearLayout自定义高亮背景的方法,包括了Android布局之LinearLayout自定义高亮背景的方法的使用技巧和注意事项,需要的朋友参考一下

本文实例讲述了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布局layout技巧总结》

希望本文所述对大家Android程序设计有所帮助。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#yiidian.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。