如何更改“导航”抽屉中所选项目的默认蓝色

时间:2013-12-05 02:34:20

标签: android navigation-drawer

我尝试使用android:listSelector,但只有当我点击listview单元格时,它才有效,如何更改所选单元格的高亮颜色,以便单元格将保持用该颜色突出显示? 非常感谢。

highlight in blue

highlight in orange

2 个答案:

答案 0 :(得分:16)

将此添加到您用于显示列表视图元素的布局

android:background="?android:attr/activatedBackgroundIndicator" 

使用以下内容创建文件res / drawable / my_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:drawable="@color/blue" />
    <item android:drawable="@android:color/transparent" />
</selector>

将@ color / blue替换为您选择的颜色。 然后,在您的主题中,添加以下行:

<item name="android:activatedBackgroundIndicator">@drawable/my_background</item>

答案 1 :(得分:0)

在这种情况下,您可能需要实现自己的适配器,并返回自定义布局,其背景颜色设置为“以橙色突出显示”。像这样:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View your_custom_view = null;

        if (convertView == null) {
            your_custom_view = LayoutInflater.from(context).inflate(R.layout.your_custom_view_layout, null);
        } else {
            your_custom_view = convertView;
        }

        return your_custom_view;
    }