2

In my Application I want to show gradient status bar. Also i have used BottomNavigationView. So issue is when i am doing status bar gradient the bottom navigation bar of android overlaps the BottomNavigationView.

I have tried below solutions :

  1. how to set status bar background as gradient color or a drawable in android
  2. Google Now gradient/shadow on status bar & navigation bar
  3. How to apply gradient to status bar in android?
  4. How to remove button bar at the bottom screen

My code is as below :

-- > In java code i tried :

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow();
            w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

Issue :: With this java code i have achieved status bar issue but bottom navigation bar of android overlaps the BottomNavigationView.

-- > Also I have tried in style with :

<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowIsTranslucent">true</item>

Issue :: But getting some dark color status bar by this code.

-- > Also I have tried immersive mode of android :

View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        // Set the content to appear under the system bars so that the
                        // content doesn't resize when the system bars hide and show.
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        // Hide the nav bar and status bar
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN);

Issue :: But it hides the status bar and bottom navigation which i don't want to.

******************* EDIT *******************

Tried in activity :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

In layout :

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

In style :

 <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:windowActionBar">false</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowTranslucentNavigation">false</item>
        <item name="android:navigationBarColor">#000</item>
        <item name="colorControlNormal">#FFFFFF</item>
 </style>

Any kind of help would be appreciable. Thank you !

Annie
  • 2,397
  • 3
  • 18
  • 26
  • @NileshRathod I am getting white status bar instead of this with your given answer. I have diffrent layout for toolbar i have given fitSystemWindow true there and also added this in bottom navigation view activity. also set the transperent primary dark. still no luck. can you check – Annie Oct 04 '18 at 06:32
  • 1
    can u please edit your question with related code and expected output so i can try to help you – AskNilesh Oct 04 '18 at 06:33
  • @NileshRathod Please check edited question. My device is 6.0.1 – Annie Oct 04 '18 at 06:37
  • and where is the image for expected output – AskNilesh Oct 04 '18 at 06:40
  • Same as you have given in your answer it is expected one. and getting output as white status bar.. nav bar is perfect now.. can't post the image actually – Annie Oct 04 '18 at 06:42
  • 1
    Test case make `android.support.design.widget.CoordinatorLayout` your rootlayout – AskNilesh Oct 04 '18 at 06:45

1 Answers1

3

You above code is working fine for me

You need to change your root layout

Make CoordinatorLayout as your root layout

Use

android.support.design.widget.CoordinatorLayout

Instead of

RelativeLayout

SEE the output using RelativeLayout

enter image description here

Output using android.support.design.widget.CoordinatorLayout

enter image description here

AskNilesh
  • 67,701
  • 16
  • 123
  • 163