android一个LinearLayout中具有几个控件,想要使那几个控件在LinearLayout被点击时,有颜色变化

直接设置控件的android:background属性为@drawable/xxxx , 这样点击布局时里边的控件都会变色,具体代码:


<LinearLayout
    android:id="@+id/personality_setting_linear_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/personal_center_personality_setting_image_selector"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="个性设置"
        android:textColor="@drawable/personal_center_text_selector"
        android:textSize="15dp"
        android:layout_gravity="center"/>

LinearLayout>

personal_center_personality_setting_image_selector.xml文件

xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@mipmap/personality_setting_pressed" android:state_pressed="true"/>
    <item android:drawable="@mipmap/personality_setting_pressed" android:state_selected="true"/>
    <item android:drawable="@mipmap/personality_setting_pressed" android:state_checked="true"/>
    <item android:drawable="@mipmap/personality_setting"/>
selector>



personal_center_text_selector.xml文件

xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    
    <item android:state_pressed="true" android:color="#cccccc"/>

    <item android:state_pressed="false" android:color="@color/white"/>


selector>


你可能感兴趣的:(智慧酒店,控件点击变色)