Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom action bar with navigation drawer?

I tried using Custom Action bar as:

bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        bar.setCustomView(R.layout.xyz);

but navigation drawer becomes invisible.

like image 545
Madhav Bhattarai Avatar asked Jan 10 '14 08:01

Madhav Bhattarai


2 Answers

I had the same problem, but I found a way to go around the problem. You need to set:

getActionBar().setCustomView(R.layout.xyz);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);

Then, it will show navigation drawer + icon.

If you don't want the icon to be visible, you can put a transparent image (just make transparent image transparent.png and put in drawable folder) instead of app icon. You can do that by defining new style for Action Bar (styles.xml):

<style name="Theme.MyAppTheme" parent="android:style/Theme.Holo.Light">
     <item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
</style>
<style name="Theme.MyAppTheme.ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
    <item name="android:icon">@drawable/transparent</item>
</style>
like image 139
didi Avatar answered Sep 23 '22 14:09

didi


For me worked:

getActionBar().setCustomView(R.layout.xyz); getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);

like image 26
SpyZip Avatar answered Sep 22 '22 14:09

SpyZip