Could not find android.view.Window.setStatusBarColor method

On devices up to 5.0, I get the following error:

I/dalvikvm: Could not find method android.view.Window.setStatusBarColor, referenced from method onCreateView
W/dalvikvm: VFY: unable to resolve virtual method 14897: Landroid/view/Window;.setStatusBarColor (I)V

and code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getActivity().getWindow();
    window.setStatusBarColor(Color.RED);
}
+4
source share
1 answer

Give it a try! He works for me. Hope works for you too.

if (android.os.Build.VERSION.SDK_INT >= 23) {
            Window window = this.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(this.getResources().getColor(R.color.colorPrimaryDark, this.getTheme()));
            window.setNavigationBarColor(this.getResources().getColor(R.color.white, this.getTheme()));
        }
0
source

Source: https://habr.com/ru/post/1611393/


All Articles