Java Code Examples for android.support.v7.widget.Toolbar#requestLayout()

The following examples show how to use android.support.v7.widget.Toolbar#requestLayout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BottomToolbarPhone.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the height and title text appearance of the provided toolbar so that its style is
 * consistent with BottomToolbarPhone.
 * @param otherToolbar The other {@link Toolbar} to style.
 */
public void setOtherToolbarStyle(Toolbar otherToolbar) {
    // Android's Toolbar class typically changes its height based on device orientation.
    // BottomToolbarPhone has a fixed height. Update |toolbar| to match.
    otherToolbar.getLayoutParams().height = getHeight();

    // Android Toolbar action buttons are aligned based on the minimum height.
    int extraTopMargin = getExtraTopMargin();
    otherToolbar.setMinimumHeight(getHeight() - extraTopMargin);

    otherToolbar.setTitleTextAppearance(
            otherToolbar.getContext(), R.style.BottomSheetContentTitle);
    ApiCompatibilityUtils.setPaddingRelative(otherToolbar,
            ApiCompatibilityUtils.getPaddingStart(otherToolbar),
            otherToolbar.getPaddingTop() + extraTopMargin,
            ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar.getPaddingBottom());

    otherToolbar.requestLayout();
}
 
Example 2
Source File: CollapsingToolbarLayoutManager.java    From react-native-collapsing-toolbar with MIT License 5 votes vote down vote up
@Override
public void addView(CollapsingToolbarLayoutView parent, View child, int index) {
    super.addView(parent, child, index);
    if (child instanceof Toolbar) {
        Toolbar toolbar = (Toolbar) child;
        int toolbarHeight = (int) PixelUtil.toPixelFromDIP(height);
        CollapsingToolbarLayout.LayoutParams params = new CollapsingToolbarLayout.LayoutParams(
            CollapsingToolbarLayout.LayoutParams.MATCH_PARENT,
            toolbarHeight
        );
        params.setCollapseMode(CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN);
        toolbar.setLayoutParams(params);
        toolbar.requestLayout();
    }
}
 
Example 3
Source File: StatusBarUtil.java    From SeeWeather with Apache License 2.0 5 votes vote down vote up
public static void setImmersiveStatusBarToolbar(@NonNull Toolbar toolbar, Context context) {
    ViewGroup.MarginLayoutParams toolLayoutParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
    toolLayoutParams.height = EnvUtil.getStatusBarHeight() + EnvUtil.getActionBarSize(context);
    toolbar.setLayoutParams(toolLayoutParams);
    toolbar.setPadding(0, EnvUtil.getStatusBarHeight(), 0, 0);
    toolbar.requestLayout();
}
 
Example 4
Source File: NestedRecyclerViewAlbumHolder.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
@Override
public void onSelectorModeEnter() {
    final View rootView = ((Activity) nestedRecyclerView.getContext())
            .findViewById(R.id.root_view);

    final Toolbar toolbar = rootView.findViewById(R.id.toolbar);

    if (theme.darkStatusBarIconsInSelectorMode()) {
        Util.setDarkStatusBarIcons(rootView);
    } else {
        Util.setLightStatusBarIcons(rootView);
    }

    View.OnClickListener onClickListener
            = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            cancelSelectorMode();
        }
    };

    //create selector-toolbar
    final Toolbar selectorToolbar = SelectorModeUtil.getSelectorModeToolbar(
            getContext(), onClickListener,
            NestedRecyclerViewAlbumHolder.this);

    selectorToolbar.setPadding(toolbar.getPaddingLeft(),
            toolbar.getPaddingTop(),
            toolbar.getPaddingRight(),
            toolbar.getPaddingBottom());

    //add selector-toolbar
    ((ViewGroup) toolbar.getParent()).addView(selectorToolbar,
            toolbar.getLayoutParams());

    selectorToolbar.requestLayout();

    //animate selector-toolbar
    selectorToolbar.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    selectorToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                    selectorToolbar.setTranslationY(-selectorToolbar.getHeight());
                    selectorToolbar.animate().translationY(0);
                }
            });
}