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:
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:
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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With