gpt4 book ai didi

android - 操作栏没有完全隐藏(只有文本和按钮)

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

我已经搜索了解决方案,但似乎没有为我的问题找到任何答案。我浏览了在这里找到的几个可能的解决方案,但所有这些解决方案最终都遇到了同样的问题。

上下文: 我有一个 FragmentContainer,它在每个页面中都包含一个 ViewpagerRecyclerView。当我单击 RecyclerView 中的一个项目时,它会打开一个新的不同的 FragmentContainer2,其中包含一个包含所选卡片详细信息的 ViewPager,我可以滑动阅读不同的卡片。

我想做什么:当我在 RecyclerView 中选择一个项目时,我想要 appBar GONE。

问题:当我点击 RecyclerView 的任何项目并加载新的 ViewPager 时,appBar 按钮和标题消失了,但背景没有!

这里有两张appBar的状态截图,一张是ViewPager,另一张是:

FragmentContainer 包含一个 ViewPager 和一个 RecyclerView:

FragmentContainer that Holds a ViewPager with RecyclerView:

FragmentContainer 包含带有新闻详细信息的 ViewPager:

FragmentContainer that holds a ViewPager with the news detail

显示和隐藏工具栏/ float 操作按钮的方法:

    public void setToolbarAndFabVisibility(Boolean trueOrFale){

ActionBar actionBar = getSupportActionBar();
if(trueOrFale!=null){
if(trueOrFale){
if (actionBar != null) {
actionBar.show();
}
fab.setVisibility(View.VISIBLE);
}else{
if (actionBar != null) {
actionBar.hide();
}
fab.setVisibility(View.GONE);
}
}
}

activity_main.xml:

<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">

<include layout="@layout/app_bar_main"/>

<android.support.design.widget.NavigationView
android:id="@+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:headerLayout="@layout/nav_header"
app:menu="@menu/menu" />

app_bar_main.xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">

<include layout="@layout/toolbar"/>

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

<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_pressed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="20dp"
android:src="@drawable/favourite_button"
app:fabSize="mini"
app:layout_anchor="@id/fragment_container"
app:layout_anchorGravity="bottom|right|end" />

两个 xml 都用适当的标签关闭。由于某种原因,此处的预览未显示。

知道我可能在哪里失败了吗?我在一项 Activity 中拥有一切。

如果我可以在这里发布任何其他可能有帮助的内容,请告诉我。感谢您抽出时间。

编辑;抱歉,我忘记包含 toolbar.xml:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways|snap">

<Button
android:id="@+id/favourites_button"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:background="@drawable/favourite_button" />

<Button
android:id="@+id/bookmarked_button"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:background="@drawable/bookmarked_button" />

<Button
android:id="@+id/history_button"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_history_white_24dp" />

最佳答案

使用这个:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();

关于android - 操作栏没有完全隐藏(只有文本和按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38300428/

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