2

I am using :

https://github.com/iPaulPro/SlidingMenu

library to implement Facebook like sliding menu, along with ActionBarSherlock library.

The BehindContentView in my case is a ListFragment.

1. Click on an Image to get the behindView (calling toggle();).

2. onListItemClicked takes to an Activity_2 displaying the text of the item clicked.

3. in this Activity_2 when i click device back button i get the main Activity_1 but the behindView is open. Usually in Facebook or Google+ the behavior is that, the behindView is hidden when you come back to Activity_1 from any other Activity.

4. Moreover on Activity_2 even after having these lines, the home doesn't seem to work(nothing happens when i click the home button).

    ActionBar bar = this.getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setHomeButtonEnabled(true);

How to solve step 3 and 4??

Thank You

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226

4 Answers4

6
SlidingMenu menu;

    @Override
public void onBackPressed() {
    if (menu.isMenuShowing()) {
        menu.showContent(true);
        return;
    }

    super.onBackPressed();
}

Boom. on back press in the activity if menu is out, it will just go away

dimetil
  • 3,851
  • 2
  • 29
  • 47
PSchuette
  • 4,463
  • 3
  • 19
  • 21
4

to hide the sliding menu

on onListItemClicked call hide() OR toggle()

for Home button ActionBar its must work, just handle it like this

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // you code
        return true;
    }
JafarKhQ
  • 8,676
  • 3
  • 35
  • 45
  • But i cant use toggle(). in a Fragment which extends SherlockListFragment. toggle() is available only in classes which extent SlidingFragmentActivity. – Archie.bpgc Oct 09 '12 at 08:10
  • so you have the slidingMenu in activity, and the onListItemClicked on fragment. if true. make a listener in your fragment and implement it on the activity – JafarKhQ Oct 09 '12 at 08:21
3

To hide the sliding menu and to open neede intent you need to give intent you want to open on iten click. Here is small example

private SlideMenu slidemenu
// this is from code. no XML declaration necessary, but you won't get state restored after rotation.
slidemenu = new SlideMenu(this, R.menu.slide, this, 333);
// this inflates the menu from XML. open/closed state will be restored after rotation, but you'll have to call init.
slidemenu = (SlideMenu) findViewById(R.id.slideMenu);
slidemenu.init(this, R.menu.IntentName, this, 333);

I used the coboltforge.slidemenu library.

I think it would be similar in iPaulPro/SlidingMenu library.

JNI_OnLoad
  • 5,472
  • 4
  • 35
  • 60
0
@Override 
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        getSlidingMenu().toggle(true);
        return false;
    } else {
        return super.onKeyUp(keyCode, event);
    }
}

Just place this in your Activity.