'How to remove app bar in fragment without .NoActionBar in themes
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>
Solution 1:[1]
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][1] [1]: https://i.stack.imgur.com/czroh.png
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | serhataal |