本文整理了Java中android.support.v7.widget.Toolbar.setLayoutParams()
方法的一些代码示例,展示了Toolbar.setLayoutParams()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolbar.setLayoutParams()
方法的具体详情如下:
包路径:android.support.v7.widget.Toolbar
类名称:Toolbar
方法名:setLayoutParams
暂无
代码示例来源:origin: xinghongfei/LookLook
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar
.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
mFragmentContainer.setPadding(mFragmentContainer.getPaddingLeft(),
insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize
(MainActivity.this),
mFragmentContainer.getPaddingRight() + insets.getSystemWindowInsetRight(), // landscape
mFragmentContainer.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams)
statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
代码示例来源:origin: TheFinestArtist/FinestWebView-Android
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(toolbarScrollFlags);
toolbar.setLayoutParams(params);
代码示例来源:origin: GeekGhost/Ghost
private void setTitleHeight(View view) {
if (view != null) {
ColorRelativeLayout title = (ColorRelativeLayout) view.findViewById(R.id.title);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
if (title != null) {
ViewGroup.LayoutParams lp = title.getLayoutParams();
lp.height = ScreenUtil.dip2px(getContext(), 48);
title.setLayoutParams(lp);
title.setPadding(0, 0, 0, 0);
}
if (TAG.equals(MineFragment.class.getSimpleName())) {
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
ViewGroup.LayoutParams lp = toolbar.getLayoutParams();
lp.height = ScreenUtil.dip2px(getContext(), 48);
toolbar.setLayoutParams(lp);
}
}
}
}
代码示例来源:origin: SharryChoo/SToolbar
@Override
public void setLayoutParams(ViewGroup.LayoutParams params) {
// Lock heightExcludePadding always is WRAP_CONTENT.
if (params.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
}
super.setLayoutParams(params);
}
代码示例来源:origin: chaychan/TouTiao
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
toolbar.setLayoutParams(lp);
toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
toolbar.setTag(true);
代码示例来源:origin: chaychan/TouTiao
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
toolbar.setLayoutParams(lp);
toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
toolbar.setTag(true);
代码示例来源:origin: chaychan/TouTiao
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
toolbar.setLayoutParams(lp);
toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
toolbar.setTag(true);
代码示例来源:origin: chaychan/TouTiao
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
toolbar.setLayoutParams(lp);
toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
toolbar.setTag(true);
代码示例来源:origin: yangchong211/YCAudioPlayer
private void initToolBar() {
int statusBarHeight = BarUtils.getStatusBarHeight();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(50));
params.topMargin = statusBarHeight;
toolbar.setLayoutParams(params);
}
代码示例来源:origin: SpikeKing/wcl-onboarding-demo
private void collapseToolbar(int height) {
TypedValue tv = new TypedValue();
getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
int toolBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
// 动画,height->toolBarHeight,468->168
ValueAnimator valueAnimator = ValueAnimator.ofInt(height, toolBarHeight);
valueAnimator.addUpdateListener(animation -> {
ViewGroup.LayoutParams lp = mTToolbar.getLayoutParams();
lp.height = (Integer) animation.getAnimatedValue();
mTToolbar.setLayoutParams(lp);
});
valueAnimator.start();
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mPhRecyclerAdapter.setItems(ModelItem.getFakeItems());
ViewCompat.animate(mFabBar).setStartDelay(500)
.setDuration(500).scaleX(1).scaleY(1).start();
}
});
}
代码示例来源:origin: IhorKlimov/Android-Animations
private void setupToolbarDimens() {
int h = getStatusBarHeight() + getActionBarSIze();
Log.d(LOG_TAG, "setupToolbarDimens: " + h);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, getStatusBarHeight(), 0, 0);
mBinding.toolbar.setLayoutParams(params);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
getStatusBarHeight() + getActionBarSIze() * 2
);
mBinding.background.setLayoutParams(params2);
mBinding.reveal.setLayoutParams(params2);
}
代码示例来源:origin: kollerlukas/Camera-Roll-Android-App
@Override
public void onGlobalLayout() {
// hacky way of getting window insets on pre-Lollipop
// somewhat works...
int[] screenSize = Util.getScreenSize(SettingsActivity.this);
int[] windowInsets = new int[]{
Math.abs(screenSize[0] - rootView.getLeft()),
Math.abs(screenSize[1] - rootView.getTop()),
Math.abs(screenSize[2] - rootView.getRight()),
Math.abs(screenSize[3] - rootView.getBottom())};
Log.d("MainActivity", "windowInsets: " + Arrays.toString(windowInsets));
toolbar.setPadding(toolbar.getPaddingStart(),
toolbar.getPaddingTop() + windowInsets[1],
toolbar.getPaddingEnd(),
toolbar.getPaddingBottom());
ViewGroup.MarginLayoutParams toolbarParams
= (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.leftMargin += windowInsets[0];
toolbarParams.rightMargin += windowInsets[2];
toolbar.setLayoutParams(toolbarParams);
container.setPadding(container.getPaddingStart() + windowInsets[0],
container.getPaddingTop(),
container.getPaddingEnd() + windowInsets[2],
container.getPaddingBottom() + windowInsets[3]);
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
代码示例来源:origin: AbbyJM/weather
public static void setImmersiveStatusBarToolbar(@NonNull Toolbar toolbar, Context context) {
ViewGroup.MarginLayoutParams toolLayoutParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolLayoutParams.height = getStatusBarHeight() + getActionBarSize(context);
toolbar.setLayoutParams(toolLayoutParams);
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
toolbar.requestLayout();
}
代码示例来源:origin: JmStefanAndroid/EasyBehavior
/**
* 初始化状态栏位置
*/
private void initStatus() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4以下不支持状态栏变色
//注意了,这里使用了第三方库 StatusBarUtil,目的是改变状态栏的alpha
StatusBarUtil.setTransparentForImageView(Demo1Activity.this, null);
//这里是重设我们的title布局的topMargin,StatusBarUtil提供了重设的方法,但是我们这里有两个布局
//TODO 关于为什么不把Toolbar和@layout/layout_uc_head_title放到一起,是因为需要Toolbar来占位,防止AppBarLayout折叠时将title顶出视野范围
int statusBarHeight = getStatusBarHeight(Demo1Activity.this);
CollapsingToolbarLayout.LayoutParams lp1 = (CollapsingToolbarLayout.LayoutParams) titleContainer.getLayoutParams();
lp1.topMargin = statusBarHeight;
titleContainer.setLayoutParams(lp1);
CollapsingToolbarLayout.LayoutParams lp2 = (CollapsingToolbarLayout.LayoutParams) mToolBar.getLayoutParams();
lp2.topMargin = statusBarHeight;
mToolBar.setLayoutParams(lp2);
}
}
代码示例来源:origin: 348476129/gank.io-with-MVVM
/**
* CollapsingToolbarLayout状态栏(可折叠图片)
*
* @param activity
* @param coordinatorLayout
* @param appBarLayout
* @param imageView
* @param toolbar
*/
public static void setCollapsingToolbar(Activity activity, CoordinatorLayout coordinatorLayout,
AppBarLayout appBarLayout, ImageView imageView, Toolbar toolbar) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
coordinatorLayout.setFitsSystemWindows(false);
appBarLayout.setFitsSystemWindows(false);
imageView.setFitsSystemWindows(false);
toolbar.setFitsSystemWindows(true);
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
lp.height = (int) (getStatusBarHeight(activity) +
activity.getResources().getDimension(R.dimen.abc_action_bar_default_height_material));
toolbar.setLayoutParams(lp);
setKKStatusBar(activity, R.color.statusBar);
setCollapsingToolbarStatus(appBarLayout);
}
}
代码示例来源:origin: jeanboydev/Android-Architecture
/**
* 向上需要全部滚出屏幕时设置topMargin代替fitsSystemWindows="true"
*
* @param toolbar
*/
public static void setStatusBarFits(Toolbar toolbar) {
if (toolbar == null) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (toolbar.getLayoutParams() instanceof AppBarLayout.LayoutParams) {
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.topMargin = StatusBarUtil.getStatusBarHeight(toolbar.getContext());
toolbar.setLayoutParams(params);
hideNavigationBar((Activity) toolbar.getContext());
}
}
}
代码示例来源:origin: XunMengWinter/Now
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setTitle("");
toolbar = mMaterialViewPager.getToolbar();
if (toolbar != null) {
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(true);
}
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(toolbar.getWidth(), UIHelper.getStatusBarHeight()));
}
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 0, 0);
mDrawerLayout.addDrawerListener(mDrawerToggle);
checkIsFirst();
initDrawer();
}
代码示例来源:origin: kollerlukas/Camera-Roll-Android-App
@Override
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(toolbar.getPaddingStart() /*+ insets.getSystemWindowInsetLeft()*/,
toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(),
toolbar.getPaddingEnd() /*+ insets.getSystemWindowInsetRight()*/,
toolbar.getPaddingBottom());
ViewGroup.MarginLayoutParams toolbarParams
= (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.leftMargin += insets.getSystemWindowInsetLeft();
toolbarParams.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(toolbarParams);
container.setPadding(container.getPaddingStart() + insets.getSystemWindowInsetLeft(),
container.getPaddingTop(),
container.getPaddingEnd() + insets.getSystemWindowInsetRight(),
container.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
代码示例来源:origin: kollerlukas/Camera-Roll-Android-App
@Override
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(toolbar.getPaddingStart(),
toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(),
toolbar.getPaddingEnd(),
toolbar.getPaddingBottom());
ViewGroup.MarginLayoutParams toolbarParams
= (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.leftMargin += insets.getSystemWindowInsetLeft();
toolbarParams.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(toolbarParams);
recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(),
recyclerView.getPaddingTop() + insets.getSystemWindowInsetTop(),
recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(),
recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
fab.setTranslationY(-insets.getSystemWindowInsetBottom());
fab.setTranslationX(-insets.getSystemWindowInsetRight());
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
代码示例来源:origin: kollerlukas/Camera-Roll-Android-App
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(toolbar.getPaddingStart() /*+ insets.getSystemWindowInsetLeft()*/,
toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(),
toolbar.getPaddingEnd() /*+ insets.getSystemWindowInsetRight()*/,
toolbar.getPaddingBottom());
ViewGroup.MarginLayoutParams toolbarParams
= (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.leftMargin += insets.getSystemWindowInsetLeft();
toolbarParams.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(toolbarParams);
recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(),
recyclerView.getPaddingTop() + insets.getSystemWindowInsetTop(),
recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(),
recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
fab.setTranslationY(-insets.getSystemWindowInsetBottom());
fab.setTranslationX(-insets.getSystemWindowInsetRight());
// clear this listener so insets aren't re-applied
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
内容来源于网络,如有侵权,请联系作者删除!