Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationDrawer not working correctly with SupportLibrary revision 21

Tags:

java

android

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

  • Updated the android-SDK
  • Updated the eclipse plugins
  • Updated my project build target=21 and targetSdkVersion=21

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

like image 349
Addev Avatar asked Oct 19 '22 23:10

Addev


1 Answers

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.

like image 94
Roberto Betancourt Avatar answered Oct 29 '22 14:10

Roberto Betancourt