Search code examples
androidxmlandroid-actionbarnavigation-drawerdrawerlayout

Unable to hide Action Bar while implementing Navigation Drawer


enter image description here

This is the full code of the xml.

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
        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:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start"
        tools:context=".ui.ui_elements.HomeActivity"
        >

<androidx.coordinatorlayout.widget.CoordinatorLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@style/SCREEN"
    tools:context=".ui.ui_elements.HomeActivity">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:fabCradleMargin="@dimen/_13sdp"
        android:paddingVertical="@dimen/_9sdp"
        app:fabCradleVerticalOffset="@dimen/_4sdp"
        style="@style/BOTTOMNAV"
        app:fabCradleRoundedCornerRadius="@dimen/_20sdp"
        app:addElevationShadow="true"

        >

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:menu="@menu/bottom_nav_menu"
            android:background="@drawable/transparent_background"
            app:itemIconSize="@dimen/_30sdp"

            android:layout_marginHorizontal="@dimen/_16sdp"
            app:labelVisibilityMode="unlabeled" app:itemHorizontalTranslationEnabled="false"
            />

    </com.google.android.material.bottomappbar.BottomAppBar>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/addTaskFab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabCustomSize="@dimen/_80sdp"
        app:maxImageSize="@dimen/_60sdp"
        app:srcCompat="@drawable/baseline_add_60"
        app:tint="@null"
        app:layout_anchor="@id/bottomAppbar"
        android:contentDescription="This adds creates a task"
        style="@style/FAB"
        app:backgroundTint="@null"
        tools:ignore="ContentDescription,HardcodedText" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="100"
            >
            <ImageView
                android:id="@+id/nav_menu_button_home"
                android:layout_width="@dimen/_40sdp"
                android:layout_height="@dimen/_40sdp"
                app:srcCompat="@drawable/baseline_menu_60"
                android:layout_weight="10"
                app:tint="@null"
                style="@style/NAV_MENU"
                android:clickable="true"
                android:layout_gravity="center"
                android:padding="@dimen/_5sdp"
                android:backgroundTintMode="src_in"
                android:contentDescription="@string/nav_drawer" />

            <TextView
                android:id="@+id/title"
                android:layout_weight="90"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:paddingEnd="@dimen/_40sdp"
                android:paddingStart="@dimen/_5sdp"
                android:fontFamily="@font/font_awesome_6_free_solid_900"
                android:textStyle="bold"
                android:letterSpacing="0.1"
                android:paddingVertical="@dimen/_5sdp"
                style="@style/TITLE"
                android:text="@string/app_name"
                android:textSize="@dimen/_37sdp"
                />
        </LinearLayout>
        <FrameLayout
            android:id="@+id/fragmentFrameLoader"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/_65sdp"
            />
    </LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_drawer_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/nav_drawer"
        android:backgroundTint="@color/lc3"
        app:itemTextColor="@color/lc4"
        app:itemIconTint="@color/lc1"
        app:itemIconSize="@dimen/_22sdp"
        app:subheaderTextAppearance="@color/lc1"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        />
</androidx.drawerlayout.widget.DrawerLayout>

In Activity file I did add Objects.requireNonNull(getSupportActionBar()).hide()

But regardless this bug still happens, how do I hide the actionbar?

The actionbar was hidden until I implemented the Nav Drawer feature

And YES, I do want to implement Nav Drawer without ToolBar By the way, I am doing this on API 26

Is there anything wrong in placement of views?


Solution

  • Create a custom theme that extends the base theme you are using in the app and removes the ActionBar. Add the following code to your styles.xml file

    
    <style name="AppTheme.NoActionBar" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    
    
    

    Make sure you have the Theme.AppCompat family of themes set as the activity's theme in the manifest file (AndroidManifest.xml

    <activity
        android:name=".ui.ui_elements.HomeActivity"
        android:theme="@style/AppTheme.NoActionBar"
        >