本文整理了Java中android.support.v7.widget.Toolbar.getLayoutParams()
方法的一些代码示例,展示了Toolbar.getLayoutParams()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolbar.getLayoutParams()
方法的具体详情如下:
包路径:android.support.v7.widget.Toolbar
类名称:Toolbar
方法名:getLayoutParams
暂无
代码示例来源: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: chaychan/TouTiao
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
代码示例来源:origin: chaychan/TouTiao
toolbar.setFitsSystemWindows(false);
if (toolbar.getTag() == null) {
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
代码示例来源:origin: chaychan/TouTiao
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
代码示例来源:origin: chaychan/TouTiao
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE
@Override
public void hideLoadingView() {
AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) mToolbar.getLayoutParams();
lp.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP);
super.hideLoadingView();
}
代码示例来源:origin: whyalwaysmea/AndroidDemos
private void materialCollapsingForKitkat() {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
// 设置Toolbar对顶部的距离
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) toolbar
.getLayoutParams();
layoutParams.topMargin = MeasureUtil.getStatusBarHeight(this);
}
}
}
代码示例来源:origin: wj576038874/PhotoSelector
/**
* 修正 Toolbar 的位置
* 在 Android 4.4 版本下无法显示内容在 StatusBar 下,所以无需修正 Toolbar 的位置
*
* @param toolbar toolbar
*/
public static void fixToolbar(Toolbar toolbar, Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int statusHeight = getStatusBarHeight(activity);
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) toolbar
.getLayoutParams();
layoutParams.setMargins(0, statusHeight, 0, 0);
}
}
代码示例来源: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: GitLqr/MaterialDesignDemo
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fake_fab_interactive);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mRv = (RecyclerView) findViewById(R.id.rv);
mFab = (ImageButton) findViewById(R.id.fab);
mToolbarBottomMargin = ((ViewGroup.MarginLayoutParams) mToolbar.getLayoutParams()).bottomMargin;
mFabBottomMargin = ((ViewGroup.MarginLayoutParams) mFab.getLayoutParams()).bottomMargin;
mRv.setLayoutManager(new LinearLayoutManager(this));
mRv.setAdapter(new MyAdapter(mData));
mRv.addOnScrollListener(new FakeFabScrollListener(this));
}
代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE
private void updateToolbarLayout() {
if (!mConfig.isFullScreenMode()) {
int statusBarHeight = getStatusBarHeight();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) toolbar.getLayoutParams();
lp.setMargins(0, statusBarHeight, 0, 0);
View parentView = (View) mAvatarIv.getParent();
parentView.setPadding(0, statusBarHeight, 0, 0);
}
}
代码示例来源:origin: undownding/very-base-activity
public void setToolbarAutoHidden(boolean toolbarAutoHidden) {
this.toolbarAutoHidden = toolbarAutoHidden;
AppBarLayout.LayoutParams params =
(AppBarLayout.LayoutParams) toolbar.getLayoutParams();
if (isToolbarAutoHidden()) {
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
| AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
} else {
params.setScrollFlags(0);
}
toolbar.invalidate();
}
代码示例来源:origin: Simon-Leeeeeeeee/SLWidget
/**
* 校正Toolbar的paddingTop
*/
private void fixToolbarPadding() {
if (mSwipeBackHelper != null && mToolbar != null) {
int paddingTop = 0;
if (mSwipeBackHelper.isStatusBarTransparent()) {
paddingTop = getStatusBarHeight();
}
mToolbar.setPadding(0, paddingTop, 0, 0);
ViewGroup.LayoutParams lp = mToolbar.getLayoutParams();
lp.height = paddingTop + getToolBarHeight();
}
}
代码示例来源: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: ywwynm/EverythingDone
@Override
protected void setActionbar() {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mActionbar.getLayoutParams();
params.setMargins(0, DisplayUtil.getStatusbarHeight(this), 0, 0);
mActionbar.requestLayout();
setSupportActionBar(mActionbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
updateAttachmentNumber();
mActionbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
returnToDetailActivity();
}
});
}
代码示例来源:origin: tyzlmjj/AndroidUI
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//设置toolbar高度
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP)
{
toolbar.getLayoutParams().height = getAppBarHeight();
toolbar.setPadding(toolbar.getPaddingLeft(),getStatusBarHeight(),toolbar.getPaddingRight(),toolbar.getPaddingBottom());
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
代码示例来源: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: tyzlmjj/AndroidUI
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
//设置toolbar高度和内边距
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
mToolbar.getLayoutParams().height = getAppBarHeight();
mToolbar.setPadding(mToolbar.getPaddingLeft(),
getStatusBarHeight(),
mToolbar.getPaddingRight(),
mToolbar.getPaddingBottom());
}
setSupportActionBar(mToolbar);
init();
}
内容来源于网络,如有侵权,请联系作者删除!