设置窗口状态栏的颜色会显示弹出窗口时, [英] Setting window status bar color when popup window is displayed

查看:265
本文介绍了设置窗口状态栏的颜色会显示弹出窗口时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来设置窗口的状态栏的颜色将显示一个弹出窗口时?我已经尝试使用

Is there a way to set the window status bar color when a popup window is displayed? I have tried using

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(color);

但是,这似乎并没有对棒棒堂工作

But this does not seem to work on Lollipop

推荐答案

我这个好几天挣扎着,似乎是在API 21中的错误固定在API 22

I struggled with this for days, it seems to be a bug in API 21 that was fixed in API 22

要解决它,我创建了一个PopupWindow但不是使用 MATCH_PARENT 身高,我计算出屏幕的高度和减去状态栏大小的高度。使用这个工具,在弹出的窗口显示了基本活动的状态栏的颜色

To get around it I created a PopupWindow but instead of using MATCH_PARENT as height, I calculated the height of the screen and substracted the height of the status bar size. Using this, the popup window shows with the status bar color of the underlying 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;
    }
}

我希望这可以帮助其他人可能会为此努力奋斗

I hope it helps someone else that might struggle with this

这篇关于设置窗口状态栏的颜色会显示弹出窗口时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆