I am using J.Feinstein library of sliding menu and it works great... The only problem i have is that it closes only if i touch outside the sliding menu or if i swipe from right to left from outside the sliding menu..
But what actually i want is that it will also swipe from right to left to close when i swipe it by finger on it, not only from outside of it...
I searched a lot.. In fact i read the source code of library and found the function getSlidingMenu(true); but that does not fulfill my requirement .. I am new to android... Kindly help me out and tell me how to do this..
Here is my piece of code..
public class ViewPagerActivity extends SlidingFragmentActivity{
// Tab titles
private String[] tabs = { "First", "Second", "Third" };
public ViewPagerActivity() {
super();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.viewpager);
setContentView(R.layout.pager);
// customize the SlidingMenu
final 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.setScrollBarStyle(2);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//sm.setSlidingEnabled(true);
//sm.setTouchmodeMarginThreshold(2);
getSlidingMenu().setSlidingEnabled(true);
setBehindContentView(R.layout.menu_frame);
}
}
If you want this type of sliding then use view pager with sliding....
http://javapapers.com/android/android-image-slider-tutorial/
this will surely help you and you will no have to face this kind of problem...
Related
First of all I am sorry to ask repeated questions. As this has been asked before but some how I could not understand properly.
I found a good solutions here. I followed and could add library to my project. Now I need to add left and right sliding menus to my project without action-bar. Here is the picture-
If I click any of the selected button then it should open the respective sliding page(once at a time) at the specific sides. Something like -
currently -
I am able to generate one side of the menu bar. It is working with sliding only. -
public class MainActivity extends FragmentActivity {
ViewPager viewPager;
PagerAdapter adapter;
CirclePageIndicator mIndicator;
private int mWidthScreen;
private int mHeightScreen;
private Bundle bundle;
private List<Fragment> frgScreens;
private int selectedtheme;
private Handler mHandler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from viewpager_main.xml
setContentView(R.layout.viewpager_main);
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
}
Now I want in both sides and should open menu by clicking the button
Any help will be appreciated. Please feel free to ask any queries.
Well Finally I did it. Here mBtnMenu is an ImageView.
mBtnMenu = (ImageView) findViewById(R.id.btnMenu);
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
mBtnMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// menu.showMenu();
menu.toggle();
}
});
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.
I am developing an app in which i have to use left and right menu.I googled and found SlidingMenu library of #jfeinstein
Things are working fine i am able to open both left and right menu.But The only problem is that the secondry menu opens with unnecessary extra spacing.I need to remove that extra spacing.I have attached the screen shots also.
here spacing is fine
Please let me know the solution.
But here i need to make the content fit inside the menu.
and here is Activity for displaying menu
public class BaseSlidingMenuActivity extends SlidingFragmentActivity {
private int mTitleRes;
protected ListFragment mFrag;
protected SlideLeftMenuFragment mLeftFrag;
/**
* Title for Sliding Menu.
*
* #param titleRes
*/
public BaseSlidingMenuActivity(int titleRes) {
mTitleRes = titleRes;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SlideRightMenuFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
} else {
mFrag = (ListFragment) this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
}
// customize the SlidingMenu
final SlidingMenu sm = getSlidingMenu();
sm.setMode(SlidingMenu.LEFT_RIGHT);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setSecondaryMenu(R.layout.menu_frame_two);
sm.setSecondaryShadowDrawable(R.drawable.shadowright);
mLeftFrag = new SlideLeftMenuFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame_two, mLeftFrag).commit();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// setSlidingActionBarEnabled(false);
}
Thanks in advance
I had forked a new branch to add this feature from jfeinstein's slidemenu.
https://github.com/buptcoder/SlidingMenu
in my branch, I added a new method for SlideMenu.
You can use
sm.setRightBehindOffset(200);
to adjust the right menu's width.
Any problems please let me know.
I want to remove from the arrow image from the HomeAsUpButton.
I tried removing the arrow's ImageView from the layout (nothing happens) and also tried using SupportActionBar.SetDisplayHomeAsUpEnabled(false); removes the button functionality entirely.
I'm using johnkil's SideNavigation code. Any suggestions?
Using YouTube's App as example:
With the ActionBar Sherlock, inside your Activity's onCreate method, you just need to do the following:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
If the up image does not disappear, it might be something related to the library that you referred. In my app, I use the SlidingMenu library and it works just fine (source: https://github.com/jfeinstein10/SlidingMenu)
EDIT: With the SlidingMenu library, the Activity would look like this:
public class MainAct extends SlidingFragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Sliding menu
// Here I set the menu's layout
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
MenuListFrag frag = MenuListFrag.newInstance(getSlidingMenuItems());
t.replace(R.id.menu_frame, frag);
t.commit();
// Customizing the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(0.35f);
// Hiding the ActionBar's up button
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
}
}
You can disable the action bar using this method
actionBar.setHomeButtonEnabled(false);
I was able to hide the "arrow" by setting a transparent image.
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);
}