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

The following examples show how to use android.support.v7.widget.Toolbar#getLayoutParams() . 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: FakeFabInteractiveActivity.java    From MaterialDesignDemo with MIT License 6 votes vote down vote up
@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));
}
 
Example 4
Source File: BaseActivity.java    From SwipeBack with Apache License 2.0 6 votes vote down vote up
protected void initToolbar(@IdRes int resId)
{
    Toolbar toolbar = (Toolbar) findViewById(resId);
    if(toolbar != null)
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            toolbar.getLayoutParams().height = getAppBarHeight();
            toolbar.setPadding(toolbar.getPaddingLeft(),
                    getStatusBarHeight(),
                    toolbar.getPaddingRight(),
                    toolbar.getPaddingBottom());
        }
        setSupportActionBar(toolbar);
    }
}
 
Example 5
Source File: MainActivity.java    From AndroidUI with MIT License 6 votes vote down vote up
@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();

}
 
Example 6
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 7
Source File: StatusBarUtils.java    From YiZhi with Apache License 2.0 5 votes vote down vote up
/**
 * 修正 Toolbar 的位置
 * 在 Android 4.4 版本下无法显示内容在 StatusBar 下,所以无需修正 Toolbar 的位置
 *
 * @param 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);
    }
}
 
Example 8
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 9
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 10
Source File: WXBaseNavActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
private void setToolbarLayout() {
    ViewGroup viewById = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
    LayoutInflater flater = LayoutInflater.from(this);
    View toolbar_page = flater.inflate(R.layout.widget_toolbar, null);
    Toolbar toolbar = (Toolbar) toolbar_page.findViewById(R.id.toolbar);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams
                                                                     .MATCH_PARENT,
                                                                 toolbar.getLayoutParams().height);
    ((ViewGroup)(viewById.getChildAt(0))).addView(toolbar_page,0,lp);
}
 
Example 11
Source File: ScrollingActivity.java    From AndroidUI with MIT License 5 votes vote down vote up
@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);
}
 
Example 12
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);
}