如何在没有主题中的noActionBar的情况下删除片段中的应用程序栏

发布于 2025-01-18 17:24:44 字数 2240 浏览 2 评论 0原文

我需要删除这个 home_fragment 操作栏,但我无法在 themes.xml 中编写 NoActionBar 因为底部导航无法以这种方式工作。有人有什么解决办法吗?

另外,看一下照片,这将有助于理解问题。 这是底部导航活动 XML 中给出的代码

  <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:id="@+id/container"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       style="@style/Theme.AppCompat.DayNight.NoActionBar">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />
    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/topAppBar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:title="Add player fragment"
        app:menu="@menu/top_app_bar"
        app:layout_constraintTop_toTopOf="parent"
        style="@style/Widget.MaterialComponents.Toolbar.Primary"/>


    <fragment
        android:id="@+id/nav_host_fragment_activity_bottom_navigation_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/topAppBar"
        app:navGraph="@navigation/mobile_navigation"/>
    </androidx.constraintlayout.widget.ConstraintLayout>

I need to remove this home_fragment action bar, but I can't write NoActionBar in themes.xml because bottom navigation won't work that way. Anyone has any solution?

Also, take a look at the photo, it will help understand the problem.
This is the code given in bottom navigation activity XML

  <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:id="@+id/container"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       style="@style/Theme.AppCompat.DayNight.NoActionBar">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />
    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/topAppBar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:title="Add player fragment"
        app:menu="@menu/top_app_bar"
        app:layout_constraintTop_toTopOf="parent"
        style="@style/Widget.MaterialComponents.Toolbar.Primary"/>


    <fragment
        android:id="@+id/nav_host_fragment_activity_bottom_navigation_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/topAppBar"
        app:navGraph="@navigation/mobile_navigation"/>
    </androidx.constraintlayout.widget.ConstraintLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微暖i 2025-01-25 17:24:44

您可以尝试将这两行添加到主题中。xml文件

        <!-- Customize your theme here. -->
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>

主题。xml文件看起来像这样

You can try adding these two lines to your themes.xml files

        <!-- Customize your theme here. -->
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>

Themes.xml file looks like this
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文