コード例 #1
0
 private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
   mStatusBarTintView = new View(context);
   LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
   params.gravity = Gravity.TOP;
   if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
     params.rightMargin = mConfig.getNavigationBarWidth();
   }
   mStatusBarTintView.setLayoutParams(params);
   mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
   mStatusBarTintView.setVisibility(View.GONE);
   decorViewGroup.addView(mStatusBarTintView);
 }
コード例 #2
0
 private void setupNavBarView(Context context, ViewGroup decorViewGroup) {
   mNavBarTintView = new View(context);
   LayoutParams params;
   if (mConfig.isNavigationAtBottom()) {
     params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());
     params.gravity = Gravity.BOTTOM;
   } else {
     params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT);
     params.gravity = Gravity.RIGHT;
   }
   mNavBarTintView.setLayoutParams(params);
   mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
   mNavBarTintView.setVisibility(View.GONE);
   decorViewGroup.addView(mNavBarTintView);
 }
コード例 #3
0
  /**
   * 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);
    }
  }