在布局Android蜂窝上的activatedBackgroundIndicator

use*_*584 0 layout android background list android-3.0-honeycomb

我看到新蜂窝有一个画廊样本.它会向您展示如何通过添加来更改所选文本视图的颜色

android:background="?android:attr/activatedBackgroundIndicator"
Run Code Online (Sandbox Code Playgroud)

到你的textview

但是,列表的行不仅是文本视图,还是线性布局下的视图集合.

为了获得与蜂窝图库列表选择相同的行为,我厌倦了设置此线性布局的背景但它不起作用.选定的行不会将颜色更改为蓝色.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background=" android:attr/activatedBackgroundIndicator">
<BUNCH OF OTHER VIEWS/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Com*_*are 6

你忘记了属性值?的前面android:background.

另请注意,activatedBackgroundIndicator仅适用于Android 3.0及更高版本.

  • 我能够通过编写选择器来做到这一点,例如<?xml version ="1.0"encoding ="utf-8"?> <selector xmlns:android ="http://schemas.android.com/apk/res/android"> <item name ="android:activatedBackgroundIndicator"android:drawable ="@ color/orange_color"android:state_pressed ="true"> </ item> <item android:drawable ="@ color/orange_color"android:state_activated ="true"> </ item> </ selector> (3认同)