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

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

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

Toolbar.getBackground介绍

暂无

代码示例

代码示例来源:origin: kinecosystem/kin-ecosystem-android-sdk

private void saveToolbarBackgroundColor(Bundle outState) {
  ColorDrawable colorDrawable = ((ColorDrawable) topToolBar.getBackground());
  if (colorDrawable != null) {
    outState.putInt(BACKGROUND_COLOR, colorDrawable.getColor());
  }
}

代码示例来源:origin: xuhongv/SmartHome

private void changeToolbarAlpha() {
  int scrollY = mScrollView.getScrollY();
  //快速下拉会引起瞬间scrollY<0
  if (scrollY < 0) {
    toolbar.getBackground().mutate().setAlpha(0);
    return;
  }
  //计算当前透明度比率
  float radio = Math.min(1, scrollY / (mBanner.getHeight() - toolbar.getHeight() * 1f));
  //设置透明度
  toolbar.getBackground().mutate().setAlpha((int) (radio * 0xFF));
}

代码示例来源:origin: xiaosong520/TitlebarGradient

private void TitleAlphaChange(int dy, float mHeaderHeight_px) {//设置标题栏透明度变化
  float percent = (float) Math.abs(dy) / Math.abs(mHeaderHeight_px);
  //如果是设置背景透明度,则传入的参数是int类型,取值范围0-255
  //如果是设置控件透明度,传入的参数是float类型,取值范围0.0-1.0
  //这里我们是设置背景透明度就好,因为设置控件透明度的话,返回ICON等也会变成透明的。
  //alpha 值越小越透明
  int alpha = (int) (percent * 255);
  toolbar.getBackground().setAlpha(alpha);//设置控件背景的透明度,传入int类型的参数(范围0~255)
  ivBack.getBackground().setAlpha(255 - alpha);
  ivMore.getBackground().setAlpha(255 - alpha);
  ivShoppingCart.getBackground().setAlpha(255 - alpha);
}

代码示例来源:origin: hefuyicoder/ZhihuDaily

private void bindHeaderView(boolean hasImage) {
  if (hasImage) {
    if (mActionBarToolbar != null) {
      mActionBarToolbar.getBackground().mutate().setAlpha(0);
    }
    spaceView.setVisibility(View.VISIBLE);
    rlStoryHeader.addView(mStoryHeaderView);
    mStoryHeaderView.bindData(mStory.getTitle(), mStory.getImageSource(), mStory.getImage());
  } else {
    spaceView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
        mActionBarToolbar.getHeight()));
  }
}

代码示例来源:origin: kinecosystem/kin-ecosystem-android-sdk

public void setToolbarColorWithAnim(@ColorRes int toColorRes, final int durationMilis) {
  int colorFrom = ((ColorDrawable) topToolBar.getBackground()).getColor();
  int colorTo = ContextCompat.getColor(getApplicationContext(), toColorRes);
  colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
  colorAnimation.setDuration(durationMilis); // milliseconds
  colorAnimation.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animator) {
      topToolBar.setBackgroundColor((int) animator.getAnimatedValue());
    }
  });
  colorAnimation.start();
}

代码示例来源:origin: hefuyicoder/ZhihuDaily

/**
 * 1.如果滚动量小于图片和toolbar的差值,设置toolbar透明度,坐标为0,直接返回
 * 2.如果滚动两大于差值,则开始修改toolbar的坐标,y坐标为滚动量的1中差值的差值
 */
private void changeToolbarAlpha() {
  int scrollY = scrollView.getScrollY();
  int storyHeaderViewHeight = getStoryHeaderViewHeight();
  float toolbarHeight = mActionBarToolbar.getHeight();
  float contentHeight = storyHeaderViewHeight - toolbarHeight;
  float ratio = Math.min(scrollY / contentHeight, 1.0f);
  mActionBarToolbar.getBackground().mutate().setAlpha((int) (ratio * 0xFF));
  if (scrollY <= contentHeight) {
    mActionBarToolbar.setY(0f);
    return;
  }
  boolean isPullingDown = mScrollPullDownHelper.onScrollChange(scrollY);
  float toolBarPositionY = isPullingDown ? 0 : (contentHeight - scrollY);
  mActionBarToolbar.setY(toolBarPositionY);
}

代码示例来源:origin: rohanoid5/Muzesto

horizontalRecyclerview = (RecyclerView) rootView.findViewById(R.id.queue_recyclerview_horizontal);
mToolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
mToolbar.getBackground().setAlpha(0);

代码示例来源:origin: xuhongv/SmartHome

toolbar.getBackground().mutate().setAlpha(0);

代码示例来源:origin: ywwynm/EverythingDone

private void changeColor(int colorTo) {
  mChangeColorTo = colorTo;
  int colorFrom = ((ColorDrawable) mFlRoot.getBackground()).getColor();
  quickRemindPicker.setAccentColor(colorTo);
  quickRemindPicker.pickForUI(quickRemindPicker.getPickedIndex());
  ObjectAnimator.ofObject(mFlRoot, "backgroundColor",
      new ArgbEvaluator(), colorFrom, colorTo).setDuration(600).start();
  updateDescriptions(colorTo);
  colorFrom = ((ColorDrawable) mActionbar.getBackground()).getColor();
  int alpha = Color.alpha(colorFrom);
  colorTo = DisplayUtil.getTransparentColor(colorTo, alpha);
  ObjectAnimator.ofObject(mActionbar, "backgroundColor",
      new ArgbEvaluator(), colorFrom, colorTo).setDuration(600).start();
  ObjectAnimator.ofObject(mStatusBar, "backgroundColor",
      new ArgbEvaluator(), colorFrom, colorTo).setDuration(600).start();
}

代码示例来源:origin: vickychijwani/udacity-p1-p2-popular-movies

if (animate) {
  int currentPrimaryColor;
  if (mToolbar.getBackground() instanceof ColorDrawable) {
    currentPrimaryColor = ((ColorDrawable) mToolbar.getBackground()).getColor();
  } else {
    currentPrimaryColor = ContextCompat.getColor(activity, R.color.colorPrimary);

相关文章

Toolbar类方法