0

I'm trying to add a gradient to my statusbar , this is my code :

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

it moves up the toolbar on the status bar and also covers up the navigation bar with the activity's content like this . I made my toolbar height bigger and solve the first problem but is there any way to preventing this code covering my navigation bar ?

anyway , is there any better way to add gradient to my statusbar without changing the toolbar height ?

enter image description here

Hemant N. Karmur
  • 840
  • 1
  • 7
  • 21
Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

1 Answers1

0

Just follow the following thing it will work for you, in my case its working perfect

Make layout like bellow

main_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/ic_launcher"
    android:fitsSystemWindows="true"
    tools:context=".SplashActivity">

    <androidx.appcompat.widget.AppCompatImageView
        android:layout_width="@dimen/_150sdp"
        app:layout_constraintEnd_toEndOf="parent"
        android:src="@drawable/cell_background"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_height="@dimen/_150sdp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

and bellow tow flags

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

Apply bellow theme to your screen

<style name="AppThemeTrans" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@android:color/transparent</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorControlNormal">#FFFFFF</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">@color/navigationBarColor</item> <!--Change Navigationbar background color here-->
    </style>
Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39