找不到方法android.view.Window.setStatusBarColor

找不到方法android.view.Window.setStatusBarColor,android,Android,在5.0以下的设备上,我遇到以下错误: 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 代码是: if (Build.VER

在5.0以下的设备上,我遇到以下错误:

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
代码是:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getActivity().getWindow();
    window.setStatusBarColor(Color.RED);
}
试试这条路! 它对我有用。希望也适用于你

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()));
        }

是否有另一个代码出现,您试图设置状态栏颜色,但没有像上面那样用代码包装它?不,这是唯一的地方,这就是为什么我如此困惑。