Android 点击汉堡菜单
我的动作栏有点小问题。我只能通过从左到右切换来查看我的抽屉,而我希望在单击汉堡菜单图标时看到它。以下是xml:Android 点击汉堡菜单,android,Android,我的动作栏有点小问题。我只能通过从左到右切换来查看我的抽屉,而我希望在单击汉堡菜单图标时看到它。以下是xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFC100"
android:text="bite"
android:minHeight="?attr/actionBarSize" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left">
<include layout="@layout/drawer"/>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
如果可能的话,我想保留这种代码结构
谢谢大家! 我认为ActionBarDrawerToggle需要另一个构造函数,即带有工具栏参数的构造函数
this.drawerToggle=newactionBarDrawerToggle(this,this.drawerLayout,工具栏,0,0)代码>我有一个类似的代码,工作正常,试试这个
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, 0,0) {
@Override
public void onDrawerClosed(View drawerView) {
// Code here will be triggered once the drawer closes
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
// Code here will be triggered once the drawer open
super.onDrawerOpened(drawerView);
}
};
//Setting the actionbarToggle to drawer layout
drawerLayout.setDrawerListener(actionBarDrawerToggle);
//calling sync state is necessary or else your hamburger icon wont show up
actionBarDrawerToggle.syncState();
非常感谢它的工作!我还有最后一个问题!我希望我的背景滚动在同一时间:我希望看到我的背景左半部分,当我在我的抽屉。你知道怎么做吗?再次感谢你!我不确定我是否理解你在寻找什么。当前,当我滚动查看我的抽屉时,抽屉在我上一页的前面,我希望我的上一页同时滚动。事实上,最后,我想看看我的抽屉和上一页的左边。很抱歉,我的英语不好,所以当你打开左边的抽屉时,你想让主页(背景)滚动到顶部吗?我想让主页同时向右滚动。事实上,我想让我的抽屉把主页“推”到右边。非常感谢它的工作!我还有最后一个问题!我希望我的背景滚动在同一时间:我希望看到我的背景左半部分,当我在我的抽屉。你知道怎么做吗?再次感谢你!关于你的另一个问题,你能提供一些细节吗?
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, 0,0) {
@Override
public void onDrawerClosed(View drawerView) {
// Code here will be triggered once the drawer closes
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
// Code here will be triggered once the drawer open
super.onDrawerOpened(drawerView);
}
};
//Setting the actionbarToggle to drawer layout
drawerLayout.setDrawerListener(actionBarDrawerToggle);
//calling sync state is necessary or else your hamburger icon wont show up
actionBarDrawerToggle.syncState();