Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange behavior in implementing LEFT_RIGHT sliding menu
    text
    copied!<p><strong>Dears,</strong> </p> <p>I'm new to Android, and try to use SlidingMenu in my project. I want to create an application with two sliding menus same as Facebook.</p> <p>With these steps I had crated my application: </p> <ol> <li>Download and add SlidingMenu library into my work-space. </li> <li>Download and add actionbarsherlock library to my work-space.</li> <li>In SlidingMenu library I add actionbarsherlock as a reference library. </li> <li>In SlidingMenu library, I extend <code>SlidingActivity.java</code> with actionbarsherlock: <code>public class SlidingActivity extends SherlockActivity implements SlidingActivityBase</code></li> <li>In my application, I add reference to SlidingMenu library.</li> <li>In my application, I extend my main activity to use <code>SlidingActivity</code> : <code>public class MainMenu extends SlidingActivity</code></li> </ol> <p><strong>My main activity code:</strong></p> <pre><code>import android.app.ActionBar; import android.os.Bundle; import android.view.KeyEvent; import com.actionbarsherlock.view.MenuInflater; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity; public class MainMenu extends SlidingActivity { SlidingMenu menu; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (enableHomeIconActionBack() || enableHomeIconActionSlidingMenu()) { ActionBar actionBar = getActionBar(); if (actionBar != null){ actionBar.setDisplayHomeAsUpEnabled(true); } } setContentView(R.layout.activity_main_menu); setBehindContentView(R.layout.activity_main_menu); menu = new SlidingMenu(this); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); menu.setMode(SlidingMenu.LEFT_RIGHT); menu.setShadowWidthRes(R.dimen.sliding_menu_shadow_width); menu.setShadowDrawable(R.drawable.shadow); menu.setBehindOffsetRes(R.dimen.sliding_menu_offset); menu.setFadeDegree(0.35f); menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW); menu.setMenu(R.layout.sliding_menu_frame); menu.setSecondaryMenu(R.layout.vehicles_tree); menu.setSecondaryShadowDrawable(R.drawable.shadow); } @Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.main_menu, menu); return true; } @Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (enableHomeIconActionSlidingMenu() &amp;&amp; menu != null) { menu.toggle(); } else if (enableHomeIconActionBack()) { onCustomBackPressed(); } return true; default: return super.onOptionsItemSelected(item); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: onCustomBackPressed(); return true; default: return super.onKeyDown(keyCode, event); } } // If sliding menu is showing, we need to hide it on the first back button // press. private void onCustomBackPressed() { if (menu != null &amp;&amp; menu.isMenuShowing()) { menu.toggle(); } else { this.onBackPressed(); } } /** * Sets activity home icon to have up icon and on press act as device back * button press. * * @return Activation state. */ public boolean enableHomeIconActionBack() { return true; } /** * Sets activity home icon to be as a sliding menu invoke icon and on press * call toggle command for the sliding menu. * * @return Activation state. */ public boolean enableHomeIconActionSlidingMenu() { return true; } } </code></pre> <p>Now, <code>menu.setMenu(R.layout.sliding_menu_frame);</code> will show: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFF00FF" &gt; &lt;/RelativeLayout&gt; </code></pre> <p>And <code>menu.setSecondaryMenu(R.layout.vehicles_tree);</code> will show: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF0F00FF"&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>The following snapshots describe the strange behavior:</strong> </p> <p><a href="http://img27.imageshack.us/img27/4166/47ry.jpg" rel="nofollow">Click to show image</a></p> <ol> <li>Main activity. </li> <li>When you swipe <strong>right</strong> on the <strong>screen</strong>.</li> <li>When you swipe <strong>left</strong> on the <strong>screen</strong>. </li> <li>When you swipe <strong>right</strong> from <strong>left screen edge</strong>. This activity covers the entire screen and it is showing the activity attached to <code>setBehindContentView(R.layout.activity_main_menu);</code>, I noticed that by changing the attached layout. </li> </ol> <p>I don't want the forth screen, what I'm doing wrong? </p> <p>Regards,, Ali Alaswad</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload