Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Translucent Navigation bar in Android

I'm using Translucent Navigation bar by adding below attribute to make my app mobile nav menu looks like some Google apps where mobile nav bar is a bit transparent and content will visible through it.

<item name="android:windowTranslucentNavigation">true</item>

But my output is itenter image description here

I don't want my views to go under it. I just need it when there is More content to scroll on screen like when there is a scrolling activity or in recyclerview. But at the end I need my activity views to not overlap by it.

Any suggestions please...

like image 812
Real Tech Hacks Avatar asked Nov 07 '22 00:11

Real Tech Hacks


1 Answers

You may need to apply insets to have space between bottom of the device and navigationbar. RootView is the top layout on xml file.

 rootView.setOnApplyWindowInsetsListener { view, insets ->

        recyclerview.run {
            setPadding(paddingLeft,paddingTop,paddingRight, insets.systemWindowInsetBottom)
        }

        insets
    }

With this snippet you will have transparent navigationbar but your RecyclerView will always be above navigationBar.

And add

android:clipToPadding="false"

flag, this works with RecyclerView, and other scrollable views i guess.

You can check out this medium article or Chris Bane's tivi app to get familiar with insets.

Also put an example on github

enter image description here

like image 90
Thracian Avatar answered Nov 14 '22 22:11

Thracian