2017-06-22 162 views
0

我已阅读了许多关于双抽屉的帖子,但他们都没有修复右抽屉切换问题。android双抽屉:右抽屉切换

的Android双抽屉布局:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

<!-- content here --> 

<android.support.design.widget.NavigationView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer1" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="left"/> 


<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer2" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="right"/> 

</android.support.v4.widget.DrawerLayout> 

在随后主activitiy

DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
     this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
drawerLayout.addDrawerListener(toggle); 
toggle.syncState(); 

只有一个左抽屉切换图标。右侧抽屉没有一个。 ActionBarDrawerToggle不指定哪个抽屉。

+0

当你向右滑动你的右抽屉没有打开? –

+0

刷卡可以打开右侧抽屉。有时最好有一个切换图标来告诉用户有一个正确的抽屉。 – eastwater

回答

1

我认为你可以制作一个工作周围显示你的自己的右侧抽屉的图标,把项目放在你的活动菜单中打开右侧抽屉。

把这个在您的main_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    > 

    <item 
     android:id="@+id/action_open_right_drawer" 
     android:icon="@mipmap/ic_ab_right_drawer_icon" 
     android:title="rightDrawer" 
     app:showAsAction="always" /> 
</menu> 

,并把这个在您的mainActivity

@Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.main_menu, menu); 
     return true; 
    } 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    if(item.getItemId() == R.id.action_open_right_drawer) 
     drawerLayout.openDrawer(GravityCompat.END); 

    return super.onOptionsItemSelected(item); 
} 

我敢肯定,这不是我们的最佳解决方案,但它的工作原理罚款

+0

对于习惯在操作栏中查找切换图标的用户,打开菜单项并不直观。可以让它进入动作栏吗?谢谢。 – eastwater

+0

其实这个菜单是针对你的动作吧它是充气物品在动作吧 –

+0

你试过了吗? –