Colored Icons in NavigationView

Good afternoon. Is there a way that displays colored icons in the navigation box? Do not tint them or set them to black, and each of them will have a corresponding color (highlight / background) when pressed in the navigation box.

Just like the Google Store App App Drawer.

+4
source share
3 answers

Yes, you can add a colored icon using the menu group items:

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

And to highlight the selected item Use the following code to select by default:

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

And you can select (highlight) an element by calling

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

Edit

, :

    <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" >

Edit

navigationView.setItemIconTintList(null);, .

+21

, . , , , / . .

, , :

0

You can set it in your Activity.Class

navigationView.setItemIconTintList(null);
0
source

Source: https://habr.com/ru/post/1629157/


All Articles