Using XML from an ActionBar to create a Navigation Drawer menu

0

Good morning, My first post here.

I'm having an Android project almost ready, just missing the icons in the Navigation Menu Drawer.

I used the following tutorial to put the items in the menu.

link

My code is as follows.

List<MenuItem> menuItems = createMenu();
    adapter = new ArrayAdapter<MenuItem>(
                    getActionBar().getThemedContext(),
                    R.layout.drawer_item,
                    R.id.title3,
                    menuItems);

    mDrawerListView.setAdapter(adapter);

In the tutorial it says the following: If we want an icon in each item in the menu list, simply implement an adapter with a layout that contains an image and use the icon property of the MenuItem itself to specify the image of the menu item.

The above layout already contains the image.

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/icones"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="5dp"
    android:background="@drawable/ic_medi"
     />

<TextView
    android:id="@+id/title3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/icones"
    android:layout_toEndOf="@+id/icones"
    android:layout_toRightOf="@+id/icones"
    android:gravity="center_vertical"
    android:text="Line 1"
    android:textColor="#000"
    android:textSize="15sp" />

Only the image in question keeps repeating itself and does not change in the same way as the text is.

The menu is as follows:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:id="@+id/menu_home"
    android:icon="@drawable/ic_medi"
    android:title="@string/lblleitura"
    android:showAsAction="always" />

<item
    android:id="@+id/menu_grafic_valores"
    android:icon="@drawable/ic_graf"
    android:title="@string/lblGraficoValor"
    android:showAsAction="always"/>

<item
    android:id="@+id/menu_grafic_consumo"
    android:icon="@drawable/ic_graf"
    android:title="@string/lblGraficoConsumo"
    android:showAsAction="always"/>

  <item
    android:id="@+id/menu_grafic_consumo_medio"
    android:icon="@drawable/ic_graf"
    android:title="@string/lblGraficoMedio"
    android:showAsAction="always"/>

    <item
    android:id="@+id/menu_noti"
    android:icon="@drawable/ic_noti"
    android:title="Notícias"
    android:showAsAction="always"/>

     <item
    android:id="@+id/menu_sair"
    android:icon="@drawable/ic_sair"
    android:title="Sair"
    android:showAsAction="always"/>

Only this detail is left to close the project. Thanks in advance for your help.

    
asked by anonymous 06.04.2016 / 13:28

0 answers