android.support.v7.widget.Toolbar.getViewTreeObserver()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中android.support.v7.widget.Toolbar.getViewTreeObserver()方法的一些代码示例,展示了Toolbar.getViewTreeObserver()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolbar.getViewTreeObserver()方法的具体详情如下:
包路径:android.support.v7.widget.Toolbar
类名称:Toolbar
方法名:getViewTreeObserver

Toolbar.getViewTreeObserver介绍

暂无

代码示例

代码示例来源:origin: smuyyh/BookReader

@Override
  public void onGlobalLayout() {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
      mCommonToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    } else {
      mCommonToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    }
    hideToolBarIfVisible();
  }
});

代码示例来源:origin: smuyyh/BookReader

@Override
public void initToolBar() {
  mCommonToolbar.getViewTreeObserver()
      .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
          if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
            mCommonToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
          } else {
            mCommonToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
          hideToolBarIfVisible();
        }
      });
  showDialog();
}

代码示例来源:origin: rey5137/material

private void onGlobalLayout() {
  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
  else
    mToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
  ActionMenuView menuView = getMenuView();
  for(int i = 0, count = menuView == null ? 0 : menuView.getChildCount(); i < count; i++){
    View child = menuView.getChildAt(i);
    if(mRippleStyle != 0){
      if(child.getBackground() == null || !(child.getBackground() instanceof ToolbarRippleDrawable))
        ViewUtil.setBackground(child, getBackground());
    }
  }
  if(mGroupChanged){
    animateIn();
    mGroupChanged = false;
  }
}

代码示例来源:origin: rey5137/material

/**
 * This function should be called in onPrepareOptionsMenu(Menu) of Activity that use
 * Toolbar as ActionBar, or after inflating menu.
 */
public void onPrepareMenu(){
  if(mGroupChanged || mMenuDataChanged){
    mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
    Menu menu = mToolbar.getMenu();
    for(int i = 0, count = menu.size(); i < count; i++){
      MenuItem item = menu.getItem(i);
      item.setVisible(item.getGroupId() == mCurrentGroup || item.getGroupId() == 0);
    }
    mMenuDataChanged = false;
  }
}

代码示例来源:origin: SpikeKing/wcl-onboarding-demo

@Override public boolean onPreDraw() {
    mTToolbar.getViewTreeObserver().removeOnPreDrawListener(this);
    collapseToolbar(mTToolbar.getHeight());  // Toolbar的坍塌效果
    return true;
  }
});

代码示例来源:origin: materialos/android-icon-pack

@SuppressWarnings("deprecation")
  @Override
  public void onGlobalLayout() {
    if (mToolbar.isTitleTruncated() && mTabs.getParent() == mToolbar) {
      mToolbar.removeView(mTabs);
      //noinspection ConstantConditions
      mAppBarLinear.addView(mTabs);
    }
    setTitle(currentTitle);
    mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
  }
});

代码示例来源:origin: materialos/android-icon-pack

void moveTabsIfNeeded() {
  final CharSequence currentTitle = getTitle();
  String longestTitle = null;
  for (PagesBuilder.Page page : mPages) {
    String title = getString(page.titleRes);
    if (longestTitle == null || title.length() > longestTitle.length()) {
      longestTitle = title;
    }
  }
  setTitle(longestTitle);
  if (mTabs != null) {
    ViewTreeObserver vto = mToolbar.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
      @SuppressWarnings("deprecation")
      @Override
      public void onGlobalLayout() {
        if (mToolbar.isTitleTruncated() && mTabs.getParent() == mToolbar) {
          mToolbar.removeView(mTabs);
          //noinspection ConstantConditions
          mAppBarLinear.addView(mTabs);
        }
        setTitle(currentTitle);
        mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
      }
    });
  }
}

代码示例来源:origin: SpikeKing/wcl-onboarding-demo

private void onAnimateCreate() {
  ViewCompat.animate(mTvTitle).alpha(1).start();
  mRvRecycler.setLayoutManager(new LinearLayoutManager(this));
  mRvRecycler.setItemAnimator(ItemAnimatorFactory.slidein());  // 列表项的淡入动画
  mPhRecyclerAdapter = new PhRecyclerAdapter();
  mRvRecycler.setAdapter(mPhRecyclerAdapter);
  mTToolbar.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    @Override public boolean onPreDraw() {
      mTToolbar.getViewTreeObserver().removeOnPreDrawListener(this);
      collapseToolbar(mTToolbar.getHeight());  // Toolbar的坍塌效果
      return true;
    }
  });
}

代码示例来源:origin: SmartDengg/SmartDrawing

@Override protected void setupToolBar() {
 toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back));
 final ImageButton navButtonView = Utils.getNavButtonView(toolbar);
 if (navButtonView != null) {
  toolbar.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
   @Override public boolean onPreDraw() {
    toolbar.getViewTreeObserver().removeOnPreDrawListener(this);
    Toolbar.LayoutParams layoutParams = (Toolbar.LayoutParams) titleTv.getLayoutParams();
    layoutParams.leftMargin = navButtonView.getWidth();
    toolbar.setNavigationIcon(null);
    return true;
   }
  });
 }
}

代码示例来源:origin: SmartDengg/SmartDrawing

@Override public boolean onPreDraw() {
  toolbar.getViewTreeObserver().removeOnPreDrawListener(this);
  Toolbar.LayoutParams layoutParams = (Toolbar.LayoutParams) titleTv.getLayoutParams();
  layoutParams.leftMargin = navButtonView.getWidth();
  toolbar.setNavigationIcon(null);
  return true;
 }
});

代码示例来源:origin: kollerlukas/Camera-Roll-Android-App

@Override
  public void onGlobalLayout() {
    toolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    // hacky way of getting window insets on pre-Lollipop
    // somewhat works...
    int[] screenSize = Util.getScreenSize(SetWallpaperActivity.this);
    int[] windowInsets = new int[]{
        Math.abs(screenSize[0] - toolbar.getLeft()),
        Math.abs(screenSize[1] - toolbar.getTop()),
        Math.abs(screenSize[2] - toolbar.getRight()),
        Math.abs(0)};
    toolbar.setPadding(toolbar.getPaddingStart() + windowInsets[0],
        toolbar.getPaddingTop() + windowInsets[1],
        toolbar.getPaddingEnd() + windowInsets[2],
        toolbar.getPaddingBottom());
  }
});

代码示例来源:origin: kollerlukas/Camera-Roll-Android-App

toolbar.getViewTreeObserver()
    .addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {

代码示例来源:origin: kollerlukas/Camera-Roll-Android-App

selectorToolbar.getViewTreeObserver().addOnGlobalLayoutListener(
    new ViewTreeObserver.OnGlobalLayoutListener() {
      @Override

相关文章

Toolbar类方法