Toolbar toolbar = ... // your toolbar within an AppBarLayout AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
Toolbar toolbar = findViewById(R.id.toolbar); // or however you need to do it for your code AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); params.setScrollFlags(0); // clear all scroll flags
.getLayoutParams(); lpToolbar.topMargin += insets.getSystemWindowInsetTop(); lpToolbar.leftMargin += insets.getSystemWindowInsetLeft();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // or however you need to do it for your code AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); params.setScrollFlags(0); // clear all scroll flags
Toolbar toolbar = findViewById(R.id.toolbar); // or however you need to do it for your code AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); params.setScrollFlags(0); // clear all scroll flags
if ("samsung".equals(Build.MANUFACTURER) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Toolbar toolbar = getToolbar(); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); lp.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, -47, getResources().getDisplayMetrics()); toolbar.setLayoutParams(lp); }
private void fixApi21ToolBarBug(Toolbar toolbar){ if(Build.VERSION.SDK_INT!=21) return; //only on api 21 final int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); final int result = (resourceId > 0) ? getResources().getDimensionPixelSize(resourceId) * 2 : 0; final CollapsingToolbarLayout.LayoutParams params = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); params.topMargin -= result; toolbar.setLayoutParams(params); }
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Toolbar tb = getActionBarToolbar(); if (tb != null) { int size = UIUtils.calculateActionBarSize(this); tb.setMinimumHeight(size); ViewGroup.LayoutParams lp = tb.getLayoutParams(); lp.height = size; tb.setLayoutParams(lp); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); Intent intent = getIntent(); final String cheeseName = intent.getStringExtra(EXTRA_NAME); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { int actionBarHeight = (int) (TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) - (getResources().getDimension(R.dimen.abc_action_bar_default_padding_material))*2); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) toolbar.getLayoutParams(); layoutParams.topMargin = - (actionBarHeight / 2); toolbar.setLayoutParams(layoutParams); } setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle(cheeseName); loadBackdrop(); }
final int paddingHeight = getPaddingTop() + getPaddingBottom(); int height = paddingHeight; LayoutParams lp = (LayoutParams) toolbar.getLayoutParams(); final int marginWidth = lp.rightMargin + lp.leftMargin; final int marginHeight = lp.topMargin + lp.bottomMargin;
final CoordinatorLayout.LayoutParams appbarLayoutParams = (CoordinatorLayout.LayoutParams)appbar.getLayoutParams(); final ViewGroup.LayoutParams toolbarLayoutParams = toolbar.getLayoutParams(); if (toolbarLayoutParams != null) { toolbarHeight_org = toolbarLayoutParams.height;