-1

I have added navigation drawer to an activity which contains PagerSlidingStrip.I can see the navigation drawer when I slide from left to right of screen but I can't see navigation drawer icon in action bar. Below is my code-

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/content_frame_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:background="#8E58D4"
        app:pstsIndicatorColor="#5B349E"

        app:pstsDividerColor="#8E58D4"
        app:pstsTabSwitch="true"
      />
    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tabs"
        android:layout_alignParentBottom="true" />


</RelativeLayout>

    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
    </android.support.v4.widget.DrawerLayout>
Android Developer
  • 9,157
  • 18
  • 82
  • 139

6 Answers6

1

Use

         ActionBar actionBar = getSupportActionBar();
        actionBar .setDisplayHomeAsUpEnabled(true);
        actionbar.setDisplayShowHomeEnabled(true);
           actionBar.setHomeButtonEnabled(true); 

or

and use

getActionBar().setDisplayHomeAsUpEnabled(true); // also required
    if (Build.VERSION.SDK_INT >= 18) {
        getActionBar().setHomeAsUpIndicator(
            getResources().getDrawable(R.drawable.ic_navigation_drawer));
    }
Subhalaxmi
  • 5,687
  • 3
  • 26
  • 42
1

add this

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
}
Android Android
  • 724
  • 1
  • 7
  • 20
1

try this for visible your menu icon.

        actionBar = getActionBar();
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setIcon(R.drawable.menu);

and override onOptionsItemSelected like below for open drawer

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        //Open your drawer here
        break;
    }
    return super.onOptionsItemSelected(item);
}
Lokesh
  • 3,247
  • 2
  • 33
  • 62
1

Add the below code

/**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
Anas Ahamed
  • 186
  • 10
0

Use this

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

this may help you

N J
  • 27,217
  • 13
  • 76
  • 96
0

remove this line, because this is causing your action bar to be non mutable

final ActionBar actionBar = getSupportActionBar();

and have this

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

and change Action bar title by overriding this

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getSupportActionBar().setTitle(mTitle);
}
Pankaj Nimgade
  • 4,529
  • 3
  • 20
  • 30