代码之家  ›  专栏  ›  技术社区  ›  hashik

停止工具栏中的活动以片段形式显示

  •  0
  • hashik  · 技术社区  · 6 年前

    我的活动的当前布局:

    <?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"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
        <include
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/main_toolbar"
            layout="@layout/main_toolbar"/>
    
        <FrameLayout
            android:id="@+id/flMainContainer"
            android:layout_below="@id/main_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        </RelativeLayout>
    
        <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:menu="@menu/drawer_view"
            app:headerLayout="@layout/header"/>
    
    
    </android.support.v4.widget.DrawerLayout>
    

    因此,它本质上只是一个工具栏和一个框架布局(这是一个由片段填充的容器)。因此,每个片段最终都会有这个工具栏,我只想在 MainActivity . 我该怎么解决这个问题?有些片段有自己的工具栏,但因为只有 FrameLayout 在活动被片段的布局替换的情况下,活动的工具栏始终存在。

    如果我给一个片段指定了它自己的工具栏,那么活动的工具栏仍将显示在片段工具栏的上方-我希望它替换工具栏。

    在我的AndroidManifest中,我将我的主题设置为 NoActionBar

    感谢您的帮助!

    3 回复  |  直到 6 年前
        1
  •  1
  •   Santanu Sur    6 年前

    在您的 first 中的碎片 onViewCreated(..) 使用此选项:-

     if (getActivity()!=null) 
          getActivity().findViewById(R.id.main_toolbar).setVisibility(View.GONE);
    
        2
  •  -1
  •   KMI    6 年前

    如果活动中不需要工具栏。从布局中删除此代码:

    <include android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/main_toolbar" layout="@layout/main_toolbar"/>
    
        3
  •  -1
  •   KMI    6 年前

    如果活动中不需要工具栏。从布局中删除此代码

    <include 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:id="@+id/main_toolbar" 
    layout="@layout/main_toolbar"/>