Exemplo n.º 1
0
  /**
   * snippet from https://github.com/niorgai/StatusBarCompat
   *
   * <p>直接使用会引起NavigationView上面空白一部分,需要将其margin - statusBarHeight
   */
  @TargetApi(19)
  private static void tianKeng(Activity activity, int statusColor, NavigationView navigationView) {
    Window window = activity.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    int statusBarHeight = getStatusBarHeight(activity);

    ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);

    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();
      // if margin top has already set, just skip.
      if (lp != null && lp.topMargin < statusBarHeight && lp.height != statusBarHeight) {
        // do not use fitsSystemWindows
        ViewCompat.setFitsSystemWindows(mChildView, false);
        // add margin to content
        lp.topMargin += statusBarHeight;
        mChildView.setLayoutParams(lp);
      }
    }

    View statusBarView = mContentView.getChildAt(0);
    if (statusBarView != null
        && statusBarView.getLayoutParams() != null
        && statusBarView.getLayoutParams().height == statusBarHeight) {
      // if fake status bar view exist, we can setBackgroundColor and return.
      statusBarView.setBackgroundColor(statusColor);
      return;
    }
    statusBarView = new View(activity);
    ViewGroup.LayoutParams lp =
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
    statusBarView.setBackgroundColor(statusColor);
    mContentView.addView(statusBarView, 0, lp);

    DrawerLayout.LayoutParams nvLp = (DrawerLayout.LayoutParams) navigationView.getLayoutParams();
    nvLp.topMargin -= statusBarHeight;
    navigationView.setLayoutParams(nvLp);
  }
  private void initView() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    RelativeLayout menu = (RelativeLayout) findViewById(R.id.menu);
    int width =
        getResources().getDisplayMetrics().widthPixels - DensityUtil.dip2px(mContext, 56 - 8);
    DrawerLayout.LayoutParams params =
        (android.support.v4.widget.DrawerLayout.LayoutParams) menu.getLayoutParams();
    params.width = width;
    menu.setLayoutParams(params);
    drawerLayout.setDrawerListener(
        new DrawerLayout.DrawerListener() {
          @Override
          public void onDrawerSlide(View view, float v) {}

          @Override
          public void onDrawerOpened(View view) {
            closePopView();
            updateLockStatus();
          }

          @Override
          public void onDrawerClosed(View view) {}

          @Override
          public void onDrawerStateChanged(int i) {}
        });

    tv_lock_status = (TextView) findViewById(R.id.tv_lock_status);
    drawer_logo = (ImageView) findViewById(R.id.drawer_logo);

    actionView = (ActionView) findViewById(R.id.btn_more);
    tv_tab_box = (TextView) findViewById(R.id.tab_box);
    tv_tab_lock = (TextView) findViewById(R.id.tab_lock);

    // tab_thumb
    tab_thumb = findViewById(R.id.tab_thumb);
    RelativeLayout.LayoutParams thumbLp = (RelativeLayout.LayoutParams) tab_thumb.getLayoutParams();
    thumbLp.width = 0;
    tab_thumb.requestLayout();

    // vp_main
    vp_main = (ViewPager) findViewById(R.id.vp_main);
    mainAdapter = new MainPagerAdapter(mContext);
    vp_main.setAdapter(mainAdapter);
    vp_main.setOnPageChangeListener(new PagerListener());

    // pop
    popView = findViewById(R.id.layout_pop);
    pop_background = findViewById(R.id.pop_background);
    pop_background.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            closePopView();
          }
        });
    pop_background.setVisibility(View.INVISIBLE);

    // image info
    btn_menu = (ImageView) findViewById(R.id.btn_menu);

    // txt
    txt_drawer_version_num = (TextView) findViewById(R.id.txt_drawer_version_num);
    txt_drawer_info_reply = (TextView) findViewById(R.id.txt_drawer_info_reply);
  }