android selector 和 layer-list复合使用

来源:互联网 发布:软件开发进度 编辑:程序博客网 时间:2024/05/14 03:30

在我们写android布局的时候我们需要用到selector 和layer-list,

他们之间可以嵌套使用的,但是不能直接嵌套,不然不会生效,需要先写好layer-list布局,如下

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
        >
        <solid android:color="@color/popup_window_press_color"></solid>
        <stroke android:color="@color/popup_window_press_color" android:width="0.1dp"></stroke>
        </shape>
    </item>
</layer-list >


之后再selector 布局中引用,代码如下

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/list_item_bg_dropdown_popwd_press"></item>
    <item android:drawable="@drawable/list_item_bg_dropdown_popwd"></item>
</selector >

这样写来就十分方便


而且selector也可以嵌套使用

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xxx="http://schemas.android.com/apk/res/xxx>

<item xxx:state_middle_v="true" xxx:state_single_h="true" android:drawable="@drawable/list_item_bg" />
  </selector>

但是一般不需嵌套,除了一些自定义了操作

1 0