gpt4 book ai didi

android - 从 viewpager 中的特定 fragment 隐藏工具栏和标签布局

转载 作者:行者123 更新时间:2023-11-29 17:20:57 25 4
gpt4 key购买 nike

我使用一个 Activity 和四个 Fragments . fragment 123Viewpager Fragments和 fragment 4Detail Fragment单击列表项时替换 fragment 3。不幸的是,当详细 fragment 替换主 fragment 时,它会添加一个 Toolbar。和后退按钮以及现有工具栏和 Tablayout .但是,我想用这个替换现有的工具栏和标签布局。

问题:如何在不创建新 Activity 的情况下实现这一目标?

主 fragment 。具有所需的工具栏和标签布局。

enter image description here

细节 fragment 。有新的工具栏(需要)和原始工具栏和标签布局(不需要)

enter image description here

MainActivity.XML

<?xml version="1.0" encoding="utf-8"?>
<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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/black_process_2"/>

</android.support.design.widget.AppBarLayout>

DetailFragment.XML

<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.allison.viewpagermasterdetail.ItemDetailActivity"
tools:ignore="MergeRootFrame">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">

<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

</android.support.v7.widget.Toolbar>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<TextView
android:id="@+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"/>

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/stat_notify_chat"
app:layout_anchor="@+id/item_detail_container"
app:layout_anchorGravity="top|end" />

最佳答案

当您打开详细信息 fragment 调用时:

toolbar.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);

@Override
public void onBackPressed() {
if (currentFragment instanceOf DetailFragment) {
toolbar.setVisibility(View.VISIBILE);
tabLayout.setVisibility(View.VISIBLE);
}
...
}

关于android - 从 viewpager 中的特定 fragment 隐藏工具栏和标签布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36562282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com