Android slide menu that slide from both sides left and right - android

I'm trying to make sliding drawer menu like the one in the Facebook app. I navigated many questions like this amazing one here.
and found a lot of libraries but all of them slide from left to right or from right to left in different one. I want to make it slide from both sides, left to right and right to left via two buttons in the top bar. Can any one help me with this.
Thanks in advance.

this is the one I use and does exactly what you want:
SlidingMenu
You will have to implement the button feature yourself but it shouldn't be too hard!
EDIT:
An example:
SlidingMenu menuS = new SlidingMenu(this);
menuS.setMode(SlidingMenu.LEFT_RIGHT);
menuS.setMenu(R.layout.slideout_list);
menuS.setSecondaryMenu(R.layout.slideout_list2);
As the code shows you need to set the mode to LEFT_RIGHT and must specify a layout for both the left menu (setMenu()) and the right menu (setSecondaryMenu()) along with the other options specifying menu size and shadows etc.

Try this
https://github.com/srikanthgr/FacebookSlideOutmenu
implement this in to your project, This is exactly what you want.

There is a branch for a right to left sliding menu of the jfeinstein's SlidingMenu original here:
https://github.com/jfeinstein10/SlidingMenu/tree/slidingright
Alternatively, there is Simon's implementation which has simple configurations for making the switch from Left-to-Right and Right-to-Left here: https://github.com/SimonVT/android-menudrawer. There is a simple example on the page.
Although, I'm not one to publicly voice an opinion, I find Simon's library a tad easier to use. ;-)
That being said, I don't, however, take away absolutely any credit from jfeinstein either. His library powers one of my better selling apps. :-)

This question is now very old, but it has been built into Android now. So if people are searching and come across this post, hit up the Navigation Drawer section on the developer pages of Android.
http://developer.android.com/design/patterns/navigation-drawer.html

Use this one, it's good for you :
abstract public class BaseSlideFragmentActivity extends SlidingFragmentActivity implements IActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
Utils.log(new Exception(), "[onCreate]");
super.onCreate(savedInstanceState);
getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
setBehindContentView(R.layout.menu_right);
getSupportFragmentManager().beginTransaction().replace(R.id.menuRight, new MenuRightFragment()).commit();
getSlidingMenu().setSecondaryMenu(R.layout.menu_left);
getSupportFragmentManager().beginTransaction().replace(R.id.menuLeft, new MenuLeftFragment()).commit();
getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
getSlidingMenu().setBehindOffsetRes(R.dimen.slidingmenu_offset);
getSlidingMenu().setFadeDegree(0.35f);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setSlidingActionBarEnabled(false);
}
public Activity getActivity() {
return this;
}
#Override
public MyApplication getApplicationContext() {
return (MyApplication) super.getApplicationContext();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Utils.log(new Exception(), "[onOptionsItemSelected]");
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
case R.id.setting:
if (getSlidingMenu().isMenuShowing()) {
toggle();
}
else {
showSecondaryMenu();
}
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Utils.log(new Exception(), "[onCreateOptionsMenu]");
getSupportMenuInflater().inflate(R.menu.menu_setting, menu);
return true;
}
}

#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setTitle(R.string.attach);
// set the content view
setContentView(R.layout.activity_main);
// configure the Sliding right Menu
SlidingMenu menuR = new SlidingMenu(this);
menuR.setMode(SlidingMenu.RIGHT);
menuR.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
// menuR.setShadowWidthRes(R.dimen.abc_action_bar_default_height);
// menu.setShadowDrawable(R.drawable.shadow);right menu
menuR.setBehindOffsetRes(R.dimen.abc_action_bar_default_height);
menuR.setFadeDegree(0.35f);
menuR.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menuR.setMenu(R.layout.right_menu_layout);
// configure the Sliding left Menu
SlidingMenu menuL = new SlidingMenu(this);
menuL.setMode(SlidingMenu.LEFT);
menuL.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
// menuL.setShadowWidthRes(R.dimen.abc_action_bar_default_height);
// menu.setShadowDrawable(R.drawable.shadow);left menu
menuL.setBehindOffsetRes(R.dimen.abc_action_bar_default_height);
menuL.setFadeDegree(0.35f);
menuL.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menuL.setMenu(R.layout.left_menu_layout);
}

Related

How to add options menu (either 3 dots and/or action icons) to a tabbed activity?

I started my project with the template "Tabbed Activity" and am now trying to add an options menu. I have done this before with a blank activity and it worked fine. As far as I can tell I have done all the same steps, even as outlined by the documentation: https://developer.android.com/guide/topics/ui/menus#options-menu
When I run the app, nothing shows up. I would expect to see the 3 dots icon. I also tried adding icons to see if they would show up as actions. No luck. Here's what I've got in my MainActivity.java file:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu_layout, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
switch (item.getItemId())
{
case R.id.settingsMenuItem:
ShowSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void ShowSettings() {
// TODO show settings
}
}
And this is the options menu xml file which is "options_menu_layout.xml" located in the res/menu directory:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/settingsMenuItem"
android:icon="#drawable/baseline_settings_black_48"
android:title="#string/menu_option_settings"/>
</menu>
This seems to work on a blank activity, but not in this tabbed activity. Is there something I'm missing that is required to make these compatible?
show the xml, style and manifest files.
According to the documentation of onCreateOptionsMenu(),
"You must return true for the panel to be displayed; if you return false it will not be shown."
In your code sample, you have return super.onCreateOptionsMenu(menu);.
Is there a reason for calling the parent's class method as well? (The android developer guide code sample also does a return true;)
So I would first try to change onCreateOptionsMenu() to return true; to see if the options menu shows up and as a next step investigate the need to call the parent class' super.onCreateOptionsMenu(menu).
Turns out when using the template "Tabbed Activity" the manifest file uses a "NoActionBar" version of the theme.
I deleted the last part of this line:
android:theme="#style/Theme.ExampleApp.NoActionBar">
So it is this instead:
android:theme="#style/Theme.ExampleApp">

Gmail tablet like Actionbar items

I'm trying to build an app with a split actionbar/toolbar like in the Gmail app.
Is there any view element for this behaviour or do I have to write such a toolbar myself?
The search icon is moving with the master fragment when opening the slidingDrawer.
To accomplish this you can add one of the new Toolbar widgets to each of your fragments layouts. The new Toolbar class was designed to be much more flexible than a traditional Actionbar and will work well in this split design. This post is a good overview for implementing a standalone Toolbar. For posterity's sake I've included the sample code for it below.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blah);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
// Set an OnMenuItemClickListener to handle menu item clicks
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
// Handle the menu item
return true;
}
});
// Inflate a menu to be displayed in the toolbar
toolbar.inflateMenu(R.menu.your_toolbar_menu);
}

Slidingmenu on both sides

I am Completely new to android and i've been given a task of having sliding menus on click of a buttons placed on either side of the corners. Very similar to that of Facebook app. I tried using the SherlockAction bar library and the Slidingmenu library but I don't quite understand its functioning. Please help me out.
Thanks in advance
If you need to use ABS with SlidingMenu first of all go into the SlidingActivities that you plan on using make them extend Sherlock__Activity instead of __Activity.
Then simply try:
public class FragmentsHolderActivity extends SlidingFragmentActivity {
public static boolean isChangeCategoryAllow = true;
public static ImageLoader imageLoader = ImageLoader.getInstance();
public MenuItem mRefreshMenuItem;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final SlidingMenu sm = getSlidingMenu();
sm.setFadeEnabled(false);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
// set the Above View
setContentView(R.layout.content_frame);
//add if you need dinamically customize your fragment as your liking.
/*getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new CategoryImagesListFragment())
.commit();*/
// set the Behind View
setBehindContentView(R.layout.menu_frame);
//add if you need dinamically customize the SlidingMenu as your liking.
/*getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new CategoryFragment())
.commit(); */
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
setBehindContentView will place the view in the "behind" portion of the SlidingMenu.

toggle() when home button click on slidingmenu with actionbarsherlock

Here is my MainActivity
public class MainActivity extends SherlockActivity implements ActionBar.OnNavigationListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock_Light_DarkActionBar); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Hide title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
//Enable home button
getSupportActionBar().setHomeButtonEnabled(true);
//Home as up display
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//Sliding menu
SlidingMenu menu = new SlidingMenu(getBaseContext());
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
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.slide_menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//should be something in here that makes it slide to the left
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//Used to put dark icons on light action bar
//boolean isLight = SampleList.THEME == R.style.Theme_Sherlock_Light;
menu.add("New")
.setIcon(R.drawable.contentnew)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Search")
.setIcon(R.drawable.actionsearch)
.setActionView(R.layout.collapsible_edittext)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I want to set when home button is clicked, it slides to the left. Thing is, i can't extend SlidingFragmentActivity like examples in jfeinstein10's project, because i already extended SherlockActivity. How can i achieve this?
You need to make a change in the SlidingMenu code. Make SlidingFragmentActivity extend SherlockFragmentActivity. Then add ActionBarSherlock as library project to SlidingMenu. Now your project only has to add SlidingMenu as library project, because that references ActionBarSherlock.
Quoted from https://github.com/jfeinstein10/SlidingMenu#setup-with-actionbarsherlock:
Setup with ActionBarSherlock
Setup as above.
Checkout a clean copy of ActionBarSherlock and import into your Eclipse workspace.
Add ActionBarSherlock as a dependency to SlidingMenu
Go into the SlidingActivities that you plan on using make them extend Sherlock___Activity instead of ___Activity.
You need to extend from SlidingFragmentActivity, If you don´t do it you can´t even call toggle or set the menu fragment.If you extended from SFA it would be something like this:
case android.R.id.home:
toggle();
return true;

How to use Sliding Menu with ActionBar Sherlock?

I am trying to use a sliding menu in my existing project where action bar Sherlock is used. But I am unable to do that. If you can give me a simple demo or tutorial to show me how to do so, that would be great? Do we have to use the fragments for the sliding menu?
Update:
How do I change the Activity when the user clicks on an item of the Sliding Menu list?
Is there a demo? please help.
Edit library SliderMenu to extents SherlockActivity
public class SlidingActivity extends SherlockActivity implements SlidingActivityBase {
Do as it says in https://github.com/jfeinstein10/SlidingMenu
Create your sliding layout.
In onCreate:
setBehindContentView(R.layout.slide_menu);
getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
getSlidingMenu().setShadowDrawable(R.drawable.shadow);
getSlidingMenu().setBehindOffsetRes(R.dimen.actionbar_home_width);
getSlidingMenu().setBehindScrollScale(0.25f);
And in the activity:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
}
return super.onOptionsItemSelected(item);
}
I did not find it very clear from the instructions on the (SlidingMenu GitGub)
Heres a screenshot to make it more clear:

Categories

Resources