简体   繁体   English

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

[英]How can I change the default blue color of a selected item in Navigation drawer

I tried to use android:listSelector, but it works only when I click on the listview cell, how can I change the highlight color of a selected cell, so that the cell will be stay highlighted with that color? 我尝试使用android:listSelector,但只有当我点击listview单元格时,它才有效,如何更改所选单元格的高亮颜色,以便单元格将保持用该颜色突出显示? Many thanks. 非常感谢。

highlight in blue 以蓝色突出显示

highlight in orange 以橙色突出显示

add this to your layout you use to show the elements of the listview 将此添加到您用于显示列表视图元素的布局中

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

Create a file res/drawable/my_background.xml with the following content : 使用以下内容创建文件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>

Replace the @color/blue with the color of your choice. 用您选择的颜色替换@ color / blue。 Then, in your theme, add the following line : 然后,在您的主题中,添加以下行:

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

you may need to implement your own adapter in this case, and return your custom layout which background color is set to "highlight in orange". 在这种情况下,您可能需要实现自己的适配器,并返回自定义布局,其背景颜色设置为“以橙色突出显示”。 Something like this: 像这样的东西:

    @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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改导航抽屉所选项目颜色为默认蓝色 - Changing Navigation Drawer Selected Item Color from default blue 无法在导航抽屉中更改所选项目的背景颜色 - Can't change selected item's background color in Navigation Drawer 更改导航抽屉中所选项目的背景颜色 - Change background color of selected item in navigation drawer 如何更改导航抽屉中所选项目的背景颜色 - How to change the Background color of selected item in the Navigation Drawer 如何在android导航抽屉中更改所选项目的背景颜色? - How to change the selected item's background color in android navigation drawer? 如何在按钮片段更改上更改抽屉选择的项目? - How can I change the drawer selected item on button fragment change? 如何使用java以编程方式更改导航抽屉上所选菜单项的文本和图标颜色 - How to change the text and icon color of selected menu item on Navigation Drawer programmatically using java 如何为导航抽屉上的不同所选项目设置不同的背景颜色? - How to set different background color for different selected item on Navigation Drawer? Android如何为导航抽屉中的选定项目设置背景颜色? - Android how to set the background color for selected item in navigation drawer? 如何更改包含导航抽屉中菜单的项目的项目标题字体颜色 - How do I change Item title font color for an Item that contains a menu in Navigation Drawer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM