Java Code Examples for androidx.appcompat.widget.Toolbar#setLayoutParams()

The following examples show how to use androidx.appcompat.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: MainActivity.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setupTabs() {
    ViewPager viewPager = findViewById(R.id.pager);
    TabLayout normalTabs = findViewById(R.id.tabs_normal);
    normalTabs.setupWithViewPager(viewPager, true);
    TabLayout compactTabs = findViewById(R.id.tabs_compact);
    compactTabs.setupWithViewPager(viewPager, true);
    Toolbar toolbar = findViewById(R.id.toolbar);
    if (SP.getBoolean("short_tabtitles", false)) {
        normalTabs.setVisibility(View.GONE);
        compactTabs.setVisibility(View.VISIBLE);
        toolbar.setLayoutParams(new LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.compact_height)));
    } else {
        normalTabs.setVisibility(View.VISIBLE);
        compactTabs.setVisibility(View.GONE);
        TypedValue typedValue = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
            toolbar.setLayoutParams(new LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
                    TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics())));
        }
    }
}
 
Example 2
Source File: ToolbarHelper.java    From CloudReader with Apache License 2.0 6 votes vote down vote up
/**
 * 将Toolbar高度填充到状态栏
 */
public static void initFullBar(Toolbar toolbar, AppCompatActivity activity) {
    ViewGroup.LayoutParams params = toolbar.getLayoutParams();
    params.height = DensityUtil.getStatusHeight(activity) + getSystemActionBarSize(activity);
    toolbar.setLayoutParams(params);
    toolbar.setPadding(
            toolbar.getLeft(),
            toolbar.getTop() + DensityUtil.getStatusHeight(activity),
            toolbar.getRight(),
            toolbar.getBottom()
    );
    activity.setSupportActionBar(toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
}
 
Example 3
Source File: BaseActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void adjustToolbar(Toolbar toolbar) {
    int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (statusBarResourceId > 0) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
        params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
        toolbar.setLayoutParams(params);
    }
}
 
Example 4
Source File: ThemePreviewActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
private void adjustToolbar(Toolbar toolbar) {
    int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (statusBarResourceId > 0) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
        int statusBarHeight = getResources().getDimensionPixelSize(statusBarResourceId);
        params.topMargin = statusBarHeight;
        toolbar.setLayoutParams(params);
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            ((ViewGroup.MarginLayoutParams) linearLayout.getLayoutParams()).setMargins(0,
                    TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) + statusBarHeight, 0, 0);
        }
    }
}
 
Example 5
Source File: MainActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(this,
            new int[] { R.attr.actionBarSize });
    ViewGroup.LayoutParams params = mFakeToolbar.getLayoutParams();
    params.height = ta.getDimensionPixelSize(R.attr.actionBarSize, 0);
    mFakeToolbar.setLayoutParams(params);
    ta.recycle();
    if (mToolbar != null) {
        ViewGroup group = (ViewGroup) mToolbar.getParent();
        int i = group.indexOfChild(mToolbar);
        group.removeViewAt(i);
        Toolbar replacement = new Toolbar(group.getContext());
        replacement.setPopupTheme(mToolbar.getPopupTheme());
        AppBarLayout.LayoutParams toolbarParams = new AppBarLayout.LayoutParams(
                AppBarLayout.LayoutParams.MATCH_PARENT, params.height);
        replacement.setLayoutParams(toolbarParams);
        for (int j = 0; j < mToolbar.getChildCount(); j++) {
            View v = mToolbar.getChildAt(j);
            if (v instanceof TabLayout) {
                mToolbar.removeViewAt(j);
                replacement.addView(v);
                j--;
            }
        }
        group.addView(replacement, i);
        setSupportActionBar(replacement);
        addActionBarDrawerToggle(replacement);
    }
}