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:
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:
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.
What am I doing wrong here? How do I display both the menu icon and the app logo with the correct spacing?