2

I wish to show both the dynamic hamburger icon from ActionBarDrawerToggle as well as the app icon before the title in a navigation drawer setup. Something like this:

enter image description here

If this info is of any use, I have an abstract base drawer activity which other activities are extending, to get an activity per screen from the navigation menu - mainly to avoid all the problems encountered in nested fragments when a viewpager comes in.

I've tried using a custom view in the toolbar like this:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:theme="@style/AppTheme.AppBarOverlay">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:drawableLeft="@mipmap/ic_launcher"
            android:drawablePadding="8dp"
            android:drawableStart="@mipmap/ic_launcher"
            android:gravity="center_vertical"
            android:textColor="@android:color/white"
            android:textSize="24sp" />

    </android.support.v7.widget.Toolbar>

in my DrawerLayout xml. Also tried ImageView followed by TextView. Also negative margins. Each of them gives something like this:

enter image description here

How can I decrease the space between the hamburger icon and the app icon? Below is the method I'm calling from each child activity's onCreate to initialise the stuff.

    protected void inflateActivityViewInFrame(int layoutId, int titleStringId) {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(layoutId, mFrameLayout, false);
        mFrameLayout.addView(view);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        ((TextView) toolbar.findViewById(R.id.title)).setText(titleStringId);
        setSupportActionBar(toolbar);
        final ActionBar actionBar = getSupportActionBar();

        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(true);
            mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

                public void onDrawerClosed(View view) {
                    supportInvalidateOptionsMenu();
                }

                public void onDrawerOpened(View drawerView) {
                    supportInvalidateOptionsMenu();
                }
            };
            mDrawerToggle.setDrawerIndicatorEnabled(true);
            mDrawerLayout.addDrawerListener(mDrawerToggle);
            mDrawerToggle.syncState();
        }
    }

I also tried the following combination:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:theme="@style/AppTheme.AppBarOverlay">

</android.support.v7.widget.Toolbar>

in the DrawerLayout in the xml and the following code for initialisation:

    protected void inflateActivityViewInFrame(int layoutId, int titleStringId) {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(layoutId, mFrameLayout, false);
        mFrameLayout.addView(view);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        final ActionBar actionBar = getSupportActionBar();

        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayUseLogoEnabled(true);
            mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

                public void onDrawerClosed(View view) {
                    supportInvalidateOptionsMenu();
                }

                public void onDrawerOpened(View drawerView) {
                    supportInvalidateOptionsMenu();
                }
            };
            mDrawerToggle.setDrawerIndicatorEnabled(true);
            mDrawerLayout.addDrawerListener(mDrawerToggle);
            mDrawerToggle.syncState();
        }
        toolbar.setTitle(titleStringId);
    }

This one doesn't show the app logo, even though setDisplayUseLogoEnabled(true) is used. enter image description here

What am I doing wrong here? How do I display both the menu icon and the app logo with the correct spacing?

AA_PV
  • 1,339
  • 1
  • 16
  • 24
  • Also tried setLogo() in toolbar along with actionBar.setDisplayUseLogoEnabled(true), still the same. Also, removing the title to get normal toolbar in the layout, setting title on toolbar using toolbar.setTitle() and actionBar.setDisplayShowTitleEnabled(true); in that order, again the spacing is screwed up. – AA_PV Nov 04 '16 at 15:00
  • Have also tried app:contentInsetLeft="0dp" app:contentInsetStart="0dp" in the toolbar attributes to no avail. Please help :( – AA_PV Nov 04 '16 at 16:50
  • have you solved the issue? – alex Feb 14 '17 at 09:29
  • @dit nope, I moved on to bottom navigation view pattern. Pls comment/answer if you find a solution :) – AA_PV Feb 15 '17 at 11:45
  • 1
    Refer this link. I think you get solution here. https://stackoverflow.com/questions/40717684/how-to-reduce-the-gap-between-navigation-icon-and-toolbar-title – Karuna Darekar Jul 30 '19 at 08:44

0 Answers0