Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在导航视图中显示并同步来自片段的汉堡图标?_Android_Android Fragments_Android Toolbar - Fatal编程技术网

Android 在导航视图中显示并同步来自片段的汉堡图标?

Android 在导航视图中显示并同步来自片段的汉堡图标?,android,android-fragments,android-toolbar,Android,Android Fragments,Android Toolbar,这是我的活动\u 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

这是我的
活动\u 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/drawer_layout"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:fitsSystemWindows="true" tools:openDrawer="start">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/frame_container">

        <include layout="@layout/app_bar_main" android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>

    <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_main" app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
处理导航抽屉中的点击项目:

 public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_home) {
            // Handle the camera action
        } else if (id == R.id.nav_updates) {

            UpdatesFragment fragment = new UpdatesFragment();
            android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.frame_container,fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
      } .. and so on
UpdatesFragment
具有与工具栏一起的视图。我的意思是我在为每一个片段重复工具栏

UpdatesFragment
onCreateView
方法中,我使用此代码显示我专门为
UpdatesFragment
编写的工具栏

 Toolbar toolbar = (Toolbar)view.findViewById(R.id.toolbar);
        AppCompatActivity activity = ((AppCompatActivity) getActivity());
        activity.setSupportActionBar(toolbar);
我的问题是:

  • 它显示工具栏,但没有汉堡图标
  • 我想有一个汉堡图标,如果我按下,它应该会打开导航抽屉
  • 注意:我再次重申我没有使用公共工具栏。当我执行片段事务时,我会替换所有东西,包括工具栏。每个片段都有一个工具栏。工具栏正在显示。只有汉堡包图标和它的行动是失踪

     Toolbar toolbar = (Toolbar)view.findViewById(R.id.toolbar);
            AppCompatActivity activity = ((AppCompatActivity) getActivity());
            activity.setSupportActionBar(toolbar);