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

The following examples show how to use android.support.v7.widget.Toolbar#setLayoutParams() . 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: StatusBarCompatKitKat.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static void setStatusBarColorForCollapsingToolbar(Activity activity, AppBarLayout appBarLayout, CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, int statusColor) {
    Window window = activity.getWindow();
    window.addFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
    View mContentChild = ((ViewGroup) window.findViewById(16908290)).getChildAt(0);
    mContentChild.setFitsSystemWindows(false);
    ((View) appBarLayout.getParent()).setFitsSystemWindows(false);
    appBarLayout.setFitsSystemWindows(false);
    collapsingToolbarLayout.setFitsSystemWindows(false);
    collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
    toolbar.setFitsSystemWindows(true);
    if (toolbar.getTag() == null) {
        CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
        lp.height += getStatusBarHeight(activity);
        toolbar.setLayoutParams(lp);
        toolbar.setTag(Boolean.valueOf(true));
    }
    int statusBarHeight = getStatusBarHeight(activity);
    removeFakeStatusBarViewIfExist(activity);
    removeMarginTopOfContentChild(mContentChild, statusBarHeight);
}
 
Example 2
Source File: ToolbarHelper.java    From WanAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 将Toolbar高度填充到状态栏
 */
public static void initFullBar(Toolbar toolbar, BaseActivity activity) {
    ViewGroup.LayoutParams params = toolbar.getLayoutParams();
    params.height = ScreenUtils.getStatusHeight(activity) + ViewHelper.getSystemActionBarSize(activity);
    toolbar.setLayoutParams(params);
    toolbar.setPadding(
            toolbar.getLeft(),
            toolbar.getTop() + ScreenUtils.getStatusHeight(activity),
            toolbar.getRight(),
            toolbar.getBottom()
    );
    activity.setSupportActionBar(toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
}
 
Example 3
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 4
Source File: ToolBarUtil.java    From Android-Architecture with Apache License 2.0 5 votes vote down vote up
/**
 * 向上需要全部滚出屏幕时设置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());
        }
    }
}
 
Example 5
Source File: PhotoCropActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
private Toolbar createToolbar() {
    Toolbar toolbar = new Toolbar(parentActivity);
    Toolbar.LayoutParams toolBarParams = new Toolbar.LayoutParams(
            Toolbar.LayoutParams.MATCH_PARENT,
            R.attr.actionBarSize
    );
    toolbar.setLayoutParams(toolBarParams);


    toolbar.setVisibility(View.VISIBLE);
    return toolbar;
}
 
Example 6
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 7
Source File: RemindersActivity.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reminders);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setNavigationIcon(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    mToolbar.setTitle(getString(R.string.title_activity_reminders));
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ) {
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
            int statusBarHeight = 0;
            int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                statusBarHeight = getResources().getDimensionPixelSize(resourceId);
            }

            RelativeLayout root = (RelativeLayout) findViewById(R.id.root);

            mStatusBarBg = new View(this);
            mStatusBarBg.setId(R.id.status_bar_bg);

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, statusBarHeight);
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            mStatusBarBg.setLayoutParams(lp);

            root.addView(mStatusBarBg);

            lp = (RelativeLayout.LayoutParams) mToolbar.getLayoutParams();
            lp.addRule(RelativeLayout.BELOW, R.id.status_bar_bg);
            mToolbar.setLayoutParams(lp);
        }

        setStatusBarColor(GraphicsUtil.darkenColor(getResources().getColor(R.color.primary), 0.85f));
    }

    findViewById(R.id.fab).setOnClickListener(this);
    ( (ImageView) findViewById(R.id.fab_bg) ).getDrawable().mutate().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.MULTIPLY);
}
 
Example 8
Source File: ViewUtils.java    From Mizuu with Apache License 2.0 2 votes vote down vote up
/**
 * Since Toolbar needs to be bigger than the default height in some cases,
 * this method will change the height to include the status bar on Kitkat and newer.
 * @param context
 * @param toolbar
 */
public static void setProperToolbarSize(Context context, Toolbar toolbar) {
    toolbar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            MizLib.hasKitKat() ? MizLib.getActionBarAndStatusBarHeight(context) : MizLib.getActionBarHeight(context)));
}