Reputation: 9634
i got sliding menu lib here & i want both left and right slide menu to come based on operation, in my case always left to right slide comes irrespective of the icon click. here is the code
where is the problem?. how to make both slide to work?
package com.example.simple_left_right_slider;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.slidingmenu.lib.SlidingMenu;
public class MainActivity extends FragmentActivity{
private SlidingMenu menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
menu = new SlidingMenu(this);
menu.setTouchModeAbove(SlidingMenu.LEFT_RIGHT);
menu.setMode(SlidingMenu.LEFT_RIGHT);
menu.setShadowWidthRes(R.dimen.shadow_width);
//menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.menu_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new SampleListFragment())
.commit();
menu.setSecondaryMenu(R.layout.menu_frame1);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame1, new SampleListFragment())
.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.mainmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item)
{
switch (item.getItemId()) {
case android.R.id.home:
menu.toggle();
break;
case R.id.github:
menu.toggle();
break;
}
return super.onOptionsItemSelected(item);
}
}
Upvotes: 2
Views: 2545
Reputation: 12142
This is because you are using the same menu.toggle()
for both actions: according to sources that method opens/closes the left menu. You should use showSecondaryMenu()
to open right menu instead.
Upvotes: 5