在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);
}
答案 0 :(得分:0)
试试这种方式! 它对我有用。希望也适合你。
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()));
}