【发布时间】:2018-07-27 03:41:13
【问题描述】:
我面临一个我自己无法解决的问题。
我无法使用工具栏中的汉堡图标打开我的导航抽屉,但我发现点击图标上方的区域可以打开它。
这是截图:
在上图中,我可以打开导航抽屉只有如果我点击了红色区域的某个地方,否则什么都不会发生。
创建时:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupMainViews();
configureToolBar();
configureDrawerLayout();
configureNavigationView();
}
配置工具栏:
private void configureToolBar(){
this.tbMain = findViewById(R.id.tbMain);
setSupportActionBar(tbMain);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
configureDrawerLayout:
private void configureDrawerLayout(){
dlMain = findViewById(R.id.dlMain);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, dlMain, tbMain,
R.string.navigation_drawer_open, R.string.navigation_drawer_close){
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
dlMain.addDrawerListener(toggle);
toggle.syncState();
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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/dlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
tools:context=".MainActivity">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainbackground">
<android.support.v7.widget.Toolbar
android:id="@+id/tbMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ToolBarStyle"/>
//other views...
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nvSide"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/sideview_header"
app:menu="@menu/sidemenu_items" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】: