Addev
Addev

Reputation: 32243

NavigationDrawer not working correctly with SupportLibrary revision 21

I just updated my android SDK in order to get the android 5 updates. Those are the steps I did:

Then I ran my app (wich uses the compat-v7 library) and found that the navigation drawer seems buggy. The app icon in the action bar is gone and the overall style seems incorrect (see the picture 2).

So I took the "Creating a Navigation Drawer" example and performed the following test:

Downloaded the sample project, updated the build target and targetSdk and replaced the android-support-v4.jar with the Compat-v7 library (revision 21) . Changed the ActionBarDrawerToggle import from android.support.v4... to import android.support.v7...

The result is correct:

Picture 1:

enter image description here

Then I try to swap the MainActivity parent class from Activity to ActionBarActivity, changing getActionBar() calls with getSupportActionBar() and getFragmentManager() with getSupportFragmentManager()

Also added the android:theme="@style/Theme.AppCompat" theme to the activity

It works but the app icon is missing and the options menu are not shown as an action. See screenshots below.

Picture 2:

enter image description here

How can I fix it?

UPDATES:

With the code:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayShowHomeEnabled(true);

You get the following bar:

enter image description here

It is pretty ok but I preffer the compact version, where the drawer indicator/ arrow have no padding with the icon (see image below). How can I achieve it?

enter image description here

Upvotes: 5

Views: 398

Answers (4)

Alexey
Alexey

Reputation: 4501

Maybe this will help you:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);

UPDATE: You can find the answer for your second question here:

How to change Toolbar navigation icon and options menu margin

Upvotes: 1

Sinan Kozak
Sinan Kozak

Reputation: 3386

After you switch to new ActionBarActivity, it looks like it hides home/Logo of Actionbar. And the @style/Theme.AppCompat has not Logo by default. You can enable it with .setHomeButtonEnabled(true);

Upvotes: 0

Roberto Betancourt
Roberto Betancourt

Reputation: 2515

This is actually the intended behavior for the new Material Design paradigm. According to the official documentation on Toolbar:

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

Upvotes: 2

Chris Banes
Chris Banes

Reputation: 31871

This is working as intended, the app icon is not displayed by default now. You can call the following to display the icon again.

ActionBar ab = getSupportActionBar();
ab.setHomeButtonEnabled(true);

Upvotes: 0

Related Questions