在Android Studio默认模板中更改导航抽屉图标的颜色 [英] Change color of Navigation Drawer Icon in Android Studio default template

查看:155
本文介绍了在Android Studio默认模板中更改导航抽屉图标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Studio中新的默认导航抽屉活动模板

The new default Navigation Drawer Activity template in Android Studio

在菜单文件activity_main_drawer中定义其标题和图标,如下所示:

defines its titles and icons in a menu file activity_main_drawer like this:

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_camara"
        android:icon="@drawable/ic_action_emo_cool"
        android:title="Import" />
    <item
        android:id="@+id/nav_gallery"
        android:icon="@android:drawable/ic_menu_gallery"
        android:title="Gallery" />
    <item
        android:id="@+id/nav_slideshow"
        android:icon="@android:drawable/ic_menu_slideshow"
        android:title="Slideshow" />
        ...

示例中的第一项使用红色图标:

The first item in my example uses a red icon:

但是当我运行该应用程序时,图标的颜色仍然是黑色.我已经对蓝色,绿色,黄色和紫色的图标进行了测试,但是结果是相同的.

but when I run the app, the color of the icon remains black.I have tested this for blue, green, yellow and purple icons, but the result is the same.

我读到某个地方,工具栏应使用ThemeOverlay.AppCompat.Dark.ActionBar,而我的应用程序已在styles.xml文件中使用了它:

I read somewhere that the toolbar should use ThemeOverlay.AppCompat.Dark.ActionBar and my app already uses this in the styles.xml file:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

最初,我认为这与Android Studio的缓存功能有关,因此我使缓存无效并没有运气就重新启动了Android Studio.

Initially I thought this had something to do with Android Studio's cache feature so I invalidated cache and restarted Android Studio with no luck.

推荐答案

基于@MD的注释,我要做的就是添加:

Based on @MD's comment, all I needed to do was add:

app:itemIconTint="@color/my_desired_colour"

NavigationView(位于activity_main.xml布局文件中)默认色调为黑色,但是可以使用#000000

to NavigationView (it is located in activity_main.xml layout file) The default tint is black but you can use an even darker shade of black by using #000000

 <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:itemIconTint="#000000"
    app:menu="@menu/activity_main_drawer" />

这篇关于在Android Studio默认模板中更改导航抽屉图标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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