Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set status bar with gradient drawable same as action bar?

i have tried many ways but it overlaps toolbar and status bar.Also it gives back press bottom navigation default. i have added below code-

 @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  Window w = getWindow();  w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);//allow window to extend outside of the screen.
            w.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);// override FLAG_FULLSCREEN and force the screen decorations (such as the status bar) to be shown.         w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR);            w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);           w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        super.onCreate(savedInstanceState);

    }

enter image description here

like image 898
Prachi rane Avatar asked Nov 24 '18 06:11

Prachi rane


1 Answers

Call this method before setContentView.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setStatusBarGradiant(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        Drawable background = activity.getResources().getDrawable(R.drawable.gradient_theme);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
        window.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
        window.setBackgroundDrawable(background);
    }
} 

Also make sure that you are using the theme AppTheme.NoActionBar. Check this. If it doesn't work check the other answers to the question.

To hide the bottom navigation bar use this

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

Check this for more info.

like image 153
Dev Sharma Avatar answered Nov 14 '22 22:11

Dev Sharma