0

I have a project with the sliding menu (from jeremy feinstein) and actionbarsherlock. For some reason, when the activity shows up the slide menu open automatically too.

Quick note about my app architecture: All of my activities have the slide menu integrated and on menu item click I start the related activity (with FLAG_ACTIVITY_SINGLE_TOP). All my activities extends the class shown below.

This is quite annoying because every time the user click on one item, the menu get expanded as well forcing the user to close it down.

Anyone knows what it is causing this behavior? What should I do to fix it and have the expected behavior.

I post below the concerned code:

package com.example.mypapp;

import com.example.mypapp.R;
import ocom.example.mypapp.SampleListFragment;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class MyAppBaseActivity extends SlidingFragmentActivity {

    protected ListFragment mFrag;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setBehindContentView(R.layout.menu_frame);
        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

        if (savedInstanceState == null) {
            FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
            mFrag = new SampleListFragment();
            t.replace(R.id.menu_frame, mFrag);
            t.commit();
        } else {
            mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
        }

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            toggle();
        }
        return true;
    }


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

}

Where SlidingFragmentActivity has been modified to extend SherlockFragmentActivity as suggested on official page of Jeremy Feinstein when actionbarsherlock is also in the picture.

  • what's that toggle() method? I bet that your problem is that you're calling toggle() in onPrepareOptionsMenu – Rich Jun 25 '13 at 20:44
  • Hi Rich, I think you're right but I added the toggle call in onPrepareOptionsMenu because I want to show/hide the menu also when the user clicks on option menu button. – Renato Del Gaudio Jun 28 '13 at 19:56
  • If I understood correctly, reading the official doc [http://developer.android.com/guide/topics/ui/menus.html#options-menu ] this method is invoked always for Android >= 3.x if items are available in the action bar. _On Android 3.0 and higher, the options menu is considered to always be open when menu items are presented in the action bar._ – Renato Del Gaudio Jun 28 '13 at 20:00
  • It is clear that if i remove the method the strange behavior is resolved but I loose my goal as well. How can I fix the automatic pop up and have at the same time the functionality to toggle the menu on option menu button click ? – Renato Del Gaudio Jun 28 '13 at 20:02

0 Answers0