Android 为什么工具栏中的菜单图标不出现在抽屉布局中
我想将导航抽屉功能添加到我的活动中,但左侧的默认菜单图标不会出现,尽管我向右滑动时,抽屉会打开。这是我的布局文件:Android 为什么工具栏中的菜单图标不出现在抽屉布局中,android,xml,menu,navigation-drawer,Android,Xml,Menu,Navigation Drawer,我想将导航抽屉功能添加到我的活动中,但左侧的默认菜单图标不会出现,尽管我向右滑动时,抽屉会打开。这是我的布局文件: <?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
<?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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="6dp"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_one_more"
app:menu="@menu/activity_one_more_drawer" />
</android.support.v4.widget.DrawerLayout>
以下是指向我的项目的链接:
请帮助我找出菜单未出现的原因,谢谢。您的工具栏
引用未初始化,因为工具栏mToolbar
是一个局部变量,由于您在添加当前未初始化的toogle
时使用工具栏
引用,因此该变量无效
改变这个
private void initToolbar() {
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle(getString(R.string.app_name));
mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
}
进入这个
private void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
//^^^^ initialize the reference which is being used to add toggle
setSupportActionBar(toolbar);
setTitle(getString(R.string.app_name));
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
}
private void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
//^^^^ initialize the reference which is being used to add toggle
setSupportActionBar(toolbar);
setTitle(getString(R.string.app_name));
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
}