有没有办法在显示弹出窗口时设置窗口状态栏颜色?我尝试过使用
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(color);
但这似乎不适用于 Lollipop
最佳答案
我为此苦苦挣扎了好几天,这似乎是 API 21 中的一个错误,已在 API 22 中修复
为了解决这个问题,我创建了一个 PopupWindow,但没有使用 MATCH_PARENT
作为高度,而是计算了屏幕的高度并减去状态栏大小的高度。使用此功能,弹出窗口将显示基础 Activity 的状态栏颜色
这是我使用的
private void showPopup(View popupView){
popup = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, getPopupHeight(), false);
popup.showAtLocation(getView(), Gravity.NO_GRAVITY, 0, 0);
}
private int getPopupHeight() {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
return size.y - statusBarHeight;
} else {
return ViewGroup.LayoutParams.MATCH_PARENT;
}
}
我希望它能帮助其他可能遇到此问题的人
关于android - 设置弹出窗口显示时窗口状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28228623/