现在的位置: 首页 > 综合 > 正文

android LinearLayout自定义高亮背景

2018年02月10日 ⁄ 综合 ⁄ 共 686字 ⁄ 字号 评论关闭

首先创建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>

抱歉!评论已关闭.