문제

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

도움이 되었습니까?

해결책

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;
    }

다른 팁

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

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.

@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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top