0

I've implemented BottomNavigationView with navigation graph. while setting a solid colour in navigationView as a background, it's working fine but when I set background colour with opacity it's not working properly.image with background color: #0D000000

Here is my gradle file:

implementation 'androidx.navigation:navigation-fragment-ktx:2.2.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.1'

Navigation.xml

    <?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_nav"
    app:startDestination="@id/firstBottomNavFragment">

    <fragment
        android:id="@+id/firstBottomNavFragment"
        android:name="com.healthymale.screens.home.fragment.HomeFragment"
        android:label="@string/home" />
    <fragment
        android:id="@+id/secondBottomNavFragment"
        android:name="com.healthymale.screens.home.fragment.ProgramsFragment"
        android:label="@string/programs" />
    <fragment
        android:id="@+id/thirdBottomNavFragment"
        android:name="com.healthymale.screens.home.fragment.TrackingFragment"
        android:label="@string/tracking" />

    <fragment
        android:id="@+id/fourBottomNavFragment"
        android:name="com.healthymale.screens.home.fragment.MoreFragment"
        android:label="@string/more" />

</navigation>

My Home screen xml:

<layout 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"
    tools:context=".screens.home.HomeScreen">

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


        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            app:defaultNavHost="true"
            app:navGraph="@navigation/navigation" />

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_nav_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/black_5"
            app:labelVisibilityMode="labeled"
            app:menu="@menu/menu" />
    </LinearLayout>
</layout>
Parth
  • 791
  • 7
  • 17

3 Answers3

2

You can use any drawable file for background so it will also help in reuseablity of code and most importantly you can also change it after app compilation like we used of do it in themes changes

1

I am using this code to set transparent background of the navView. You can change color and use:

navView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.transparent));
Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35
0

anyone who wants the navigation bar to transparent and also to clickable

android:background="?android:attr/windowBackground"

or

android:background="?android:selectableItemBackground"

try one of those above

necip
  • 333
  • 4
  • 11