如何在实现您的媒体库的应用中确定状态栏是否为半透明?

She*_*bic 1 android android-layout android-windowmanager

我创建了一个小库,用于将视图放置在现有视图的旁边/上方/下方(例如,“帮助”箭头或类似的东西),

MainView.getLocationOnScreen(..);
Run Code Online (Sandbox Code Playgroud)

确定主视图将在附近放置同级视图的位置。

通常,我使用以下方法通过以下方法确定主视图的顶部(Y),然后使用以下方法确定状态栏的高度:

protected boolean isTranslucentStaturBar()
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = ((Activity) mainActionView.getContext()).getWindow();

   --> return // SOME EXPRESSION TO DETERMINE IF THE STATUS BAR IS TRANSLUCENT <--- ?????
        // I Need to know what expression I need to write here
        // i.e. How to ready the flag: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
    }

    return false;
}

protected int getStatusBarHeight() {
    if (isTranslucentStaturBar()) {
        return 0;
    }

    int result = 0;
    int resourceId = mainActionView.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = mainActionView.getContext().getResources().getDimensionPixelSize(resourceId);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是Androids> = Kitkat,您实际上可以在其中将状态栏设置为半透明,并且窗口内容会散布以填充状态栏图标下方的位置。

She*_*bic 6

好的,所以在深入研究之后,我提出了以下解决方案:

protected boolean isTranslucentStatusBar()
{
    Window w = ((Activity) mainActionView.getContext()).getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    int flags = lp.flags;
    // Here I'm comparing the binary value of Translucent Status Bar with flags in the window
    if ((flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) {
        return true;
    }

    return false;
}
Run Code Online (Sandbox Code Playgroud)