Android 显示活动工具栏的折叠工具栏片段
我的片段中有一个折叠工具栏布局,显示得很好,问题是应用程序工具栏也在显示。我尝试这个解决方案:但对我来说不起作用 这是我的片段AppBarLayout:Android 显示活动工具栏的折叠工具栏片段,android,android-fragments,android-actionbar,android-actionbar-compat,android-collapsingtoolbarlayout,Android,Android Fragments,Android Actionbar,Android Actionbar Compat,Android Collapsingtoolbarlayout,我的片段中有一个折叠工具栏布局,显示得很好,问题是应用程序工具栏也在显示。我尝试这个解决方案:但对我来说不起作用 这是我的片段AppBarLayout: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:la
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/layout_bar"
android:layout_width="match_parent"
android:layout_height="192dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:contentScrim="#FFf3802b"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/brandLogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="@string/logo_icon"
android:scaleType="centerCrop"
android:src="@drawable/avatar_krono"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/fragment_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
...
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
然后,我尝试使用此行隐藏我的appToolbar,但不起作用,我的appToolbar始终显示:
((AppCompatActivity) getActivity()).getSupportActionBar().hide();
有什么建议吗?在展开此片段的活动中,您使用哪种类型的布局?也许一个协调人可以解决你的问题
在展开此片段的活动中,您使用哪种类型的布局?也许一个协调人可以解决你的问题
您的片段将替换内层,而不是Acitvity工具栏。所有工作正常的都应该与片段容器和工具栏放在一起。在代码中:
<!-- Use this LinearLayout for container -->
<LinearLayout
android:id="@+id/correct_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/appToolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
当然,我们可以使用另一种解决方案。我们可以在MainActivity中创建函数,并调用所有片段来关闭实际的工具栏(执行与您不同的其他代码)。和其他…您的片段将替换内层,但不是Acitvity工具栏。所有工作正常的都应该与片段容器和工具栏放在一起。在代码中:
<!-- Use this LinearLayout for container -->
<LinearLayout
android:id="@+id/correct_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/appToolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
当然,我们可以使用另一种解决方案。我们可以在MainActivity中创建函数,并调用所有片段来关闭实际的工具栏(执行与您不同的其他代码)。和其他…在切换正在折叠的布局片段时,将颜色更改为透明 通过此步骤,您将获得您的解决方案:
切换折叠布局片段时,将颜色更改为透明 通过此步骤,您将获得您的解决方案:
我更新了我的XML,正如您在我的片段布局中看到的,我使用了CoordinatorLayout,父活动如何?我的Activity_main.XML只是一个普通活动,有一个NavigationView(新NavigationDrawer)和一个FrameLayout来显示我的片段、我的工具栏和我的抽屉布局。。。(我更新了我的代码,你现在可以看到了)我更新了我的XML,正如你在我的片段布局中看到的,我使用CoordinatorLayout,那么父活动呢?我的Activity_main.XML只是一个普通的活动,它有一个NavigationView(新的NavigationDrawer)和一个FrameLayout来显示我的片段、我的工具栏和我的DrawerLayout。。。(我更新了我的代码,你现在可以看到)“你的片段替换了内层,但不是Acitvity工具栏”我知道。。。这就是为什么我通过调用((AppCompatActivity)getActivity()).getSupportActionBar()从de片段中获取我的活动工具栏实例,但问题是如果我可以更改de标题,为什么我不能隐藏它?我想在每个片段中创建我的工具栏,而不是在我的MainActivity中,但我不知道这是否是一个好的实践。。。我认为它会起作用,但我认为有一个更好的方法来做到这一点“你的片段取代了内层,但不是Acitvity工具栏”我知道。。。这就是为什么我通过调用((AppCompatActivity)getActivity()).getSupportActionBar()从de片段中获取我的活动工具栏实例,但问题是如果我可以更改de标题,为什么我不能隐藏它?我想在每个片段中创建我的工具栏,而不是在我的MainActivity中,但我不知道这是否是一个好的实践。。。我认为它会起作用,但我认为有更好的方法来做到这一点
<!-- Use this LinearLayout for container -->
<LinearLayout
android:id="@+id/correct_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/appToolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>