在我的导航栏中,我的列表视图图标如下所示check image。所以这意味着我已经在后台施加了图标。
我知道通过Frame Layout,我可以将图标放在图像上,但我很困惑,当它在res/menu
文件夹中声明时我怎么能这样做
menu.xml文件
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home_white_24dp"
android:title="@string/nav_item_home" />
<item
android:id="@+id/appointment_history"
android:icon="@drawable/appointment_icon"
android:title="@string/nav_history" />
<item
android:id="@+id/contact_us"
android:icon="@drawable/contact_us_icon"
android:title="@string/nav_contact_us" />
<item
android:id="@+id/nav_settings"
android:icon="@drawable/setting_icon"
android:title="@string/nav_setting" />
</group>
</menu>
Style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 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="RatingBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#00BFF3</item>
<item name="colorControlActivated">#00BFF3</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
<style name="MyCustomToolBarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">@color/colorAccent</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
V21
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
答案 0 :(得分:1)
首先,您需要将图标色调设置为空。
navigationView.setItemIconTintList(null);
然后你可以像这样创建一个xml drawable,在这个例子中我将它命名为rounded_corner_home
。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<solid android:color="#007f12" />
<corners android:radius="4dp" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/ic_home_white_24dp"/>
</item>
</layer-list>
然后更改菜单项的图标适用性。
<item
android:id="@+id/nav_home"
android:icon="@drawable/rounded_corner_home"
android:title="@string/nav_item_home" />
结果截图:Screen
答案 1 :(得分:0)
Using this code you can change the color of drawer icon :
o 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" />