Change the icons from the Navigation Drawer menu

Asked

Viewed 3,305 times

4

I would like to know how to exchange these icons:

Captura de tela de uma aplicação Android com vários uma NavigationDrawer aberta, contendo vários menus. Do lado esquerdo de cada menu, há um ícone não-relacionado com a descrição do menu, dando a entender que são ícones padrão

I found the screen, but when I click it does not show me the way to make the change but only colors in RGBA :

Captura de tela de um código XML

1 answer

5


I noticed that you are using the Default Navigation Drawer, so to change the icons and customize as you want, just go in the folder menu and in the archive activity_main_drawer.xml and make the changes as you wish.

Take an example:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:title="@string/menu1">
    <menu>
        <item
            android:icon="@drawable/ic_check_box"
            android:id="@+id/nav_um"
            android:title="@string/categoria1" />
        <item
            android:icon="@drawable/ic_check_box"
            android:id="@+id/nav_dois"
            android:title="@string/categoria2" />
        <item
            android:icon="@drawable/ic_check_box"
            android:id="@+id/nav_tres"
            android:title="@string/categoria3" />
        <item
            android:icon="@drawable/ic_check_box"
            android:id="@+id/nav_quatro"
            android:title="@string/categoria4" />
        <item
            android:icon="@drawable/ic_check_box"
            android:id="@+id/nav_cinco"
            android:title="@string/categoria5" />
        <item
            android:icon="@drawable/ic_check_box"
            android:id="@+id/nav_seis"
            android:title="@string/categoria6" />
    </menu>
    </item>
        <item android:title="@string/menu2">
        <menu>
            <item
                android:icon="@drawable/ic_check_box"
                android:id="@+id/nav_sete"
                android:title="@string/categoria7" />
            <item
                android:icon="@drawable/ic_check_box"
                android:id="@+id/nav_oito"
                android:title="@string/categoria8" />
            <item
                android:icon="@drawable/ic_check_box"
                android:id="@+id/nav_nove"
                android:title="@string/categoria9" />
            <item
                android:icon="@drawable/ic_check_box"
                android:id="@+id/nav_dez"
                android:title="@string/categoria10" />
        </menu>
    </item>
    <item android:title="@string/menu3">
        <menu>
            <item
                android:id="@+id/nav_sobre"
                android:icon="@drawable/ic_storage_24dp"
                android:title="@string/menusobre" />
            <item
                android:id="@+id/nav_sair"
                android:icon="@drawable/ic_clear_24dp"
                android:title="@string/menusair" />
        </menu>
    </item>

</menu>

Note that the Android Studio IDE offers a very useful tool, which is the Vector Asset for you to create a custom icon, just right click on the folder drawable > New > Vector Asset

inserir a descrição da imagem aqui


inserir a descrição da imagem aqui


inserir a descrição da imagem aqui


inserir a descrição da imagem aqui

See that above the new icon is in the folder drawable, so now just edit your file activity_main_drawer.xml, in that way:

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">

        <item android:title="@string/menu1">
        <menu>
            <item
                android:icon="@drawable/ic_3d_rotation_black_24dp"
                android:id="@+id/nav_um"
                android:title="@string/categoria1" />

I hope I’ve helped.

  • 2

    Man, thank you so much. You helped me so much. Now yes. Thanks so much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.