NavigationView 中的彩色图标 [英] Colored Icons In NavigationView

查看:31
本文介绍了NavigationView 中的彩色图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有没有办法在导航抽屉上显示彩色图标?不给它们着色或将它们设置为黑色,并且在导航抽屉中单击时,它们中的每一个都会具有相应的颜色(突出显示/背景).

就像 Google 商店应用程序抽屉一样.

Just like Google Store App drawer.

推荐答案

是的,您可以使用菜单组项添加彩色图标:

Yes you can add colored icon using menu group items:

<item
        android:id="@+id/drawer_artist"
        android:icon="@drawable/artist"
        android:title="Artists"/>

并突出显示选择的项目使用以下代码进行默认选择:

And for highlighting the selcted item Use the code below for default selection:

navigationView.getMenu().getItem(0).setChecked(true);

并且您可以通过调用选择(突出显示)该项目

And You can select(highlight) the item by calling

onNavigationItemSelected(navigationView.getMenu().getItem(0));

编辑

如果您使用的是导航视图,您可以编辑更改图标颜色的选项,如下所示:

If you are using navigationview you can edit option for changing the colortint of icons as follows:

    <android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:background="@drawable/bg_all"

    app:itemIconTint="@android:color/white"
    app:itemTextColor="@android:color/white"
    app:theme="@style/list_item_appearance"
    app:menu="@menu/drawer_menu" >

编辑

如果你设置了 navigationView.setItemIconTintList(null); 你会得到彩色图标.

If you set navigationView.setItemIconTintList(null); you will get colored icons.

这篇关于NavigationView 中的彩色图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆