1

I want a options menu after the drawer toggle button like this app. And I want options menu in left, write both sides (don't wanna compromise any). Can anyone tell me how to do that?

enter image description here

-: My tool bar :-

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

-: My options menu :-

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
   getMenuInflater().inflate(R.menu.option_menu, menu);
}

-: In xml :-

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

    <item
        android:id="@+id/0"
        android:icon="@drawable/ic_0"
        android:title=""
        app:showAsAction="always"
        android:orderInCategory="0"/>

    <item
        android:icon="@drawable/ic_1"
        android:orderInCategory="1"
        android:title=""
        app:showAsAction="always">
        <menu>
            <item
                android:id="@+id/2"
                android:icon="@drawable/ic_2"
                android:orderInCategory="2"
                android:title="2" />

            <item
                android:id="@+id/3"
                android:icon="@drawable/ic_3"
                android:orderInCategory="3"
                android:title="3" />

            <item
                android:id="@+id/4"
                android:icon="@drawable/ic_4"
                android:orderInCategory="4"
                android:title="4" />

            <item
                android:id="@+id/5"
                android:icon="@drawable/ic_5"
                android:orderInCategory="5"
                android:title="5" />

            <item
                android:id="@+id/6"
                android:icon="@drawable/ic_6"
                android:orderInCategory="6"
                android:title="6" />
        </menu>
    </item>
</menu>
ArghadipDasCEO
  • 177
  • 1
  • 12
  • You could create your custom `Toolbar` – Dumbo Feb 22 '18 at 15:49
  • How to do that? I don't want to set image and text views! Is there any way to align one option item in left? – ArghadipDasCEO Feb 22 '18 at 15:50
  • I think that creating `custom_toolbar.xml` with `ImageView`'s with `android:layout_gravity="start"` parameter is the only way. – Dumbo Feb 22 '18 at 15:54
  • I think apart from your solution we can do that with `toolbar.setIcon(R.drable.image)` !! – ArghadipDasCEO Feb 22 '18 at 15:57
  • I'm not sure, but I think that will replace your Drawer icon. @ArghadipDasCEO – Dumbo Feb 22 '18 at 16:03
  • no that will not replace drawer logo `toolbar.setLogo(R.drable.image)` – ArghadipDasCEO Feb 22 '18 at 16:11
  • What is the problem, exactly? You say you want your `Toolbar` like is shown in the image, but then say "I want options menu in left", while the options menu in that image appears to be on the right side. It's also unclear what "write both sides (don't wanna compromise any)" means, and why the code you've posted is not working for you. – Mike M. Feb 23 '18 at 00:35
  • Look at the toolbar carefully, it has an option menu after the drawer button and also it has options menu at the right side! I want the same thing, in both of left and right i want the options menu, but I also need the drawer button! But i was telling Ü that can we make the left menu with `toolbar.setLogo` method or not? I did it but the image appears in the middle! I hope Ü understood! :) – ArghadipDasCEO Feb 23 '18 at 03:53
  • Tell me that how can we align the `options item 0` to left (after the drawer button) and the `options item 1` to right (normal options menu position). Both of them appears right side. – ArghadipDasCEO Feb 23 '18 at 03:55
  • There's absolutely no indication that that stylized M is a menu item. And it's certainly not the standard options menu. It looks like a basic logo. Anyway, rather than trying to fiddle with the options menu items' layout, it'd be simpler to add your own `` in the ``, set its `layout_gravity` to `start|center_vertical`, and set an `OnClickListener` on it. – Mike M. Feb 23 '18 at 05:03
  • Okay, lemme try that :p – ArghadipDasCEO Feb 23 '18 at 05:04

0 Answers0