Java Code Examples for android.app.Activity#getWindow()

The following examples show how to use android.app.Activity#getWindow() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Common   File: StatusBarCompat.java    License: Apache License 2.0 6 votes vote down vote up
public static void cancelLightStatusBar(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;
    }
    if (activity == null) {
        return;
    }
    Window window = activity.getWindow();
    if (window == null) {
        return;
    }
    View decorView = window.getDecorView();
    if (decorView == null) {
        return;
    }
    decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & (~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR));
}
 
Example 2
Source Project: FamilyChat   File: ScreenUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 5.0以上切换NavigationBar颜色
 * !!!注意!!!需要在Activity的onCreate()之前调用以下方法
 */
public static void changeNavigationBarColor(Activity activity, int color)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        Window window = activity.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setNavigationBarColor(color);//切换导航栏颜色
    }
}
 
Example 3
Source Project: NineGridLayout   File: Tinter.java    License: Apache License 2.0 6 votes vote down vote up
@TargetApi(19)
private static void tint(Activity activity, boolean on) {
    Window win = activity.getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);


    Class<? extends Window> clazz = win.getClass();
    try {
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        int darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(win, darkModeFlag, darkModeFlag);
    } catch (Throwable e) {
    }
}
 
Example 4
Source Project: SprintNBA   File: ScreenUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 调整窗口的透明度  1.0f,0.5f 变暗
 *
 * @param from    from>=0&&from<=1.0f
 * @param to      to>=0&&to<=1.0f
 * @param context 当前的activity
 */
public static void dimBackground(final float from, final float to, Activity context) {
    final Window window = context.getWindow();
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
    valueAnimator.setDuration(500);
    valueAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    WindowManager.LayoutParams params = window.getAttributes();
                    params.alpha = (Float) animation.getAnimatedValue();
                    window.setAttributes(params);
                }
            });
    valueAnimator.start();
}
 
Example 5
/**
 * 设置状态栏全透明
 *
 * @param activity 需要设置的activity
 */
public static void setTransparent(Activity activity) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || activity == null) {
    return;
  }
  Window window = activity.getWindow();

  //4.4 全透明状态栏
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  }
  //5.0 全透明实现
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    int systemUiVisibility = activity.getWindow().getDecorView().getSystemUiVisibility();
    systemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    systemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_STABLE;
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
  }
}
 
Example 6
Source Project: LeisureRead   File: SystemBarHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity Activity对象
 * @param drawerLayout DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha 透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
                                          @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    return;
  }

  Window window = activity.getWindow();
  ViewGroup decorView = (ViewGroup) window.getDecorView();
  ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    drawerLayout.setStatusBarBackgroundColor(statusBarColor);

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
  } else {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  }

  setStatusBar(decorView, statusBarColor, true, true);
  setTranslucentView(decorView, alpha);

  drawerLayout.setFitsSystemWindows(false);
  drawContent.setFitsSystemWindows(true);
  ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
  drawer.setFitsSystemWindows(false);
}
 
Example 7
/**
 * Force screen to turn on if the phone is asleep.
 *
 * @param context The current Context or Activity that this method is called from
 */
public static void turnScreenOn(Activity context) {
    try {
        Window window = context.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    } catch (Exception ex) {
        Log.e("PercolateAndroidUtils", "Unable to turn on screen for activity " + context);
    }
}
 
Example 8
Source Project: MeiBaseModule   File: EyesKitKat.java    License: Apache License 2.0 5 votes vote down vote up
static void setStatusBarColor(Activity activity, int statusColor) {
    Window window = activity.getWindow();
    //设置Window为全透明
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    //获取父布局
    View mContentChild = mContentView.getChildAt(0);
    //获取状态栏高度
    int statusBarHeight = getStatusBarHeight(activity);

    //如果已经存在假状态栏则移除,防止重复添加
    removeFakeStatusBarViewIfExist(activity);
    //添加一个View来作为状态栏的填充
    addFakeStatusBarView(activity, statusColor, statusBarHeight);
    //设置子控件到状态栏的间距
    addMarginTopToContentChild(mContentChild, statusBarHeight);
    //不预留系统栏位置
    if (mContentChild != null) {
        ViewCompat.setFitsSystemWindows(mContentChild, false);
    }
    //如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡
    int action_bar_id = activity.getResources().getIdentifier("action_bar", "id", activity.getPackageName());
    View view = activity.findViewById(action_bar_id);
    if (view != null) {
        TypedValue typedValue = new TypedValue();
        if (activity.getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
            int actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources()
                    .getDisplayMetrics());
            Eyes.setContentTopPadding(activity, actionBarHeight);
        }
    }
}
 
Example 9
Source Project: androidnative.pri   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
static void setFullScreen(Map message) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ) { 
        return;
    }

    final Boolean value = (Boolean) message.get("value");
    final Activity activity = QtNative.activity();

    Runnable runnable = new Runnable () {
        public void run() {
            Window w = activity.getWindow(); // in Activity's onCreate() for instance
            View decorView = w.getDecorView();

            int config = decorView.getSystemUiVisibility();

            if (value) {
                config &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
            } else {
                config |= View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }
            decorView.setSystemUiVisibility(config);
        }
    };

    activity.runOnUiThread(runnable);

}
 
Example 10
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 11
Source Project: KUtils   File: StatusBarUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setFullScreen(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // 设置透明状态栏,这样才能让 ContentView 向上
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
}
 
Example 12
Source Project: MarkdownEditors   File: SystemBarUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity       Activity对象
 * @param drawerLayout   DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha          透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout, @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }

    Window window = activity.getWindow();
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        drawerLayout.setStatusBarBackgroundColor(statusBarColor);

        int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        window.getDecorView().setSystemUiVisibility(systemUiVisibility);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    setStatusBar(decorView, statusBarColor, true, true);
    setTranslucentView(decorView, alpha);

    drawerLayout.setFitsSystemWindows(false);
    drawContent.setFitsSystemWindows(true);
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawer.setFitsSystemWindows(false);
}
 
Example 13
public void setActivity(Activity activity) {
	super.setActivity(activity);
	Window win = activity.getWindow();
	int orientation = activity.getResources().getConfiguration().orientation;
	if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	} else {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	}
}
 
Example 14
Source Project: EasyPhotos   File: SystemUtils.java    License: Apache License 2.0 5 votes vote down vote up
private void setStatusTextBlackAndroid(Activity activity, boolean darkmode) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Window window = activity.getWindow();
        if (darkmode) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            int flag = window.getDecorView().getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            window.getDecorView().setSystemUiVisibility(flag);
        }
    }
}
 
Example 15
Source Project: KugouLayout   File: KugouLayout.java    License: MIT License 5 votes vote down vote up
private void attachToContent(Activity activity, KugouLayout kugouLayout){
    Window window = activity.getWindow();
    ViewGroup decorView = (ViewGroup)window.getDecorView();
    ViewGroup decorChild= (ViewGroup)decorView.getChildAt(0);

    decorView.removeAllViews();
    mKugouLayout.mContentContainer.addView(decorChild, decorChild.getLayoutParams());
    decorView.addView(mKugouLayout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawable(new ColorDrawable(0x0));
}
 
Example 16
Source Project: Noyze   File: SystemBarTintManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructor. Call this in the host activity onCreate method after its
 * content view has been set. You should always create new instances when
 * the host activity is recreated.
 *
 * @param activity The host activity.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public SystemBarTintManager(Activity activity) {

    Window win = activity.getWindow();
    ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // check theme attrs
        int[] attrs = {android.R.attr.windowTranslucentStatus,
                android.R.attr.windowTranslucentNavigation};
        TypedArray a = activity.obtainStyledAttributes(attrs);
        try {
            mStatusBarAvailable = a.getBoolean(0, false);
            mNavBarAvailable = a.getBoolean(1, false);
        } finally {
            a.recycle();
        }

        // check window flags
        WindowManager.LayoutParams winParams = win.getAttributes();
        int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if ((winParams.flags & bits) != 0) {
            mStatusBarAvailable = true;
        }
        bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        if ((winParams.flags & bits) != 0) {
            mNavBarAvailable = true;
        }
    }

    mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
    // device might not have virtual navigation keys
    if (!mConfig.hasNavigtionBar()) {
        mNavBarAvailable = false;
    }

    if (mStatusBarAvailable) {
        setupStatusBarView(activity, decorViewGroup);
    }
    if (mNavBarAvailable) {
        setupNavBarView(activity, decorViewGroup);
    }

}
 
Example 17
/**
 * change to full screen mode
 * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it
 */
public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
    Window window = activity.getWindow();
    ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int statusBarHeight = getStatusBarHeight(activity);

        //First translucent status bar.
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        //set child View not fill the system window
        View mChildView = mContentView.getChildAt(0);
        if (mChildView != null) {
            ViewCompat.setFitsSystemWindows(mChildView, false);
            //must call requestApplyInsets, otherwise it will have space in screen bottom
            ViewCompat.requestApplyInsets(mChildView);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //After LOLLIPOP just set LayoutParams.
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            if (hideStatusBarBackground) {
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(COLOR_TRANSLUCENT);
            } else {
                window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA));
            }
        } else {
            ViewGroup mDecorView = (ViewGroup) window.getDecorView();
            if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean) mDecorView.getTag()) {
                mChildView = mDecorView.getChildAt(0);
                //remove fake status bar view.
                mDecorView.removeView(mChildView);
                mChildView = mContentView.getChildAt(0);
                if (mChildView != null) {
                    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();
                    //cancel the margin top
                    if (lp != null && lp.topMargin >= statusBarHeight) {
                        lp.topMargin -= statusBarHeight;
                        mChildView.setLayoutParams(lp);
                    }
                }
                mDecorView.setTag(false);
            }
        }
    }
}
 
Example 18
/**
 * Constructor. Call this in the host activity onCreate method after its
 * content view has been set. You should always create new instances when
 * the host activity is recreated.
 *
 * @param activity The host activity.
 */
@TargetApi(19)
public SystemBarTintManager(Activity activity) {

    Window win = activity.getWindow();
    ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();

    // check theme attrs
    int[] attrs = {android.R.attr.windowTranslucentStatus,
            android.R.attr.windowTranslucentNavigation};
    TypedArray a = activity.obtainStyledAttributes(attrs);
    try {
        mStatusBarAvailable = a.getBoolean(0, false);
        mNavBarAvailable = a.getBoolean(1, false);
    } finally {
        a.recycle();
    }

    // check window flags
    WindowManager.LayoutParams winParams = win.getAttributes();
    int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if ((winParams.flags & bits) != 0) {
        mStatusBarAvailable = true;
    }
    bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
    if ((winParams.flags & bits) != 0) {
        mNavBarAvailable = true;
    }

    mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
    // device might not have virtual navigation keys
    if (!mConfig.hasNavigtionBar()) {
        mNavBarAvailable = false;
    }

    if (mStatusBarAvailable) {
        setupStatusBarView(activity, decorViewGroup);
    }
    if (mNavBarAvailable) {
        setupNavBarView(activity, decorViewGroup);
    }

}
 
Example 19
Source Project: FireFiles   File: SystemBarTintManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructor. Call this in the host activity onCreate method after its
 * content view has been set. You should always create new instances when
 * the host activity is recreated.
 *
 * @param activity The host activity.
 */
@TargetApi(19)
public SystemBarTintManager(Activity activity) {

    Window win = activity.getWindow();
    ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // check theme attrs
        int[] attrs = {android.R.attr.windowTranslucentStatus,
                android.R.attr.windowTranslucentNavigation};
        TypedArray a = activity.obtainStyledAttributes(attrs);
        try {
            mStatusBarAvailable = a.getBoolean(0, false);
            //mNavBarAvailable = a.getBoolean(1, false);
        } finally {
            a.recycle();
        }

        // check window flags
        WindowManager.LayoutParams winParams = win.getAttributes();
        int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if ((winParams.flags & bits) != 0) {
            mStatusBarAvailable = true;
        }
        bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        if ((winParams.flags & bits) != 0) {
            mNavBarAvailable = true;
        }
    }

    mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
    // device might not have virtual navigation keys
    if (!mConfig.hasNavigtionBar()) {
        mNavBarAvailable = false;
    }

    if (mStatusBarAvailable) {
        setupStatusBarView(activity, decorViewGroup);
    }
    if (mNavBarAvailable) {
        setupNavBarView(activity, decorViewGroup);
    }

}
 
Example 20
/**
 * 沉浸式状态栏。
 * 支持 4.4 以上版本的 MIUI 和 Flyme,以及 5.0 以上版本的其他 Android。
 *
 * @param activity 需要被设置沉浸式状态栏的 Activity。
 */
public static void translucent(Activity activity, @ColorInt int colorOn5x) {
    Window window = activity.getWindow();
    translucent(window, colorOn5x);
}