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

The following examples show how to use android.support.v7.widget.Toolbar#setPadding() . 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: 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 2
Source File: AboutActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if(Utils.hasKitKat() && !Utils.hasLollipop()){
		setTheme(R.style.Theme_Document_Translucent);
	}
	setContentView(R.layout.activity_about);

	Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
	mToolbar.setTitleTextAppearance(this, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
	if(Utils.hasKitKat() && !Utils.hasLollipop()) {
		//((LinearLayout.LayoutParams) mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
		mToolbar.setPadding(0, getStatusBarHeight(this), 0, 0);
	}
	int color = SettingsActivity.getPrimaryColor();
	mToolbar.setBackgroundColor(color);
	setSupportActionBar(mToolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setTitle(null);
	setUpDefaultStatusBar();

	initControls();
}
 
Example 3
Source File: AboutActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if(Utils.hasKitKat() && !Utils.hasLollipop()){
		setTheme(R.style.Theme_Document_Translucent);
	}
	setContentView(R.layout.activity_about);

	Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
	mToolbar.setTitleTextAppearance(this, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
	if(Utils.hasKitKat() && !Utils.hasLollipop()) {
		//((LinearLayout.LayoutParams) mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
		mToolbar.setPadding(0, getStatusBarHeight(this), 0, 0);
	}
	int color = SettingsActivity.getPrimaryColor();
	mToolbar.setBackgroundColor(color);
	setSupportActionBar(mToolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setTitle(null);
	setUpDefaultStatusBar();

	initControls();
}
 
Example 4
Source File: AboutActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if(Utils.hasKitKat() && !Utils.hasLollipop()){
		setTheme(R.style.Theme_Document_Translucent);
	}
	setContentView(R.layout.activity_about);

	Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
	mToolbar.setTitleTextAppearance(this, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
	if(Utils.hasKitKat() && !Utils.hasLollipop()) {
		//((LinearLayout.LayoutParams) mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
		mToolbar.setPadding(0, getStatusBarHeight(this), 0, 0);
	}
	int color = SettingsActivity.getPrimaryColor();
	mToolbar.setBackgroundColor(color);
	setSupportActionBar(mToolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setTitle(null);
	setUpDefaultStatusBar();

	initControls();
}
 
Example 5
Source File: BaseAppcompatActivity.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initTheme();
    setContentView(getContentViewLayoutId());
    mToolbar = (Toolbar) findViewById(R.id.actionbarToolbar);
    mToolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            smoothToTop();
        }
    });

    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        int statusBarHeight = UIUtils.getStatusBarHeight(this);
        mToolbar.setPadding(0, statusBarHeight, 0, 0);
    }
    setupActionBar();
}
 
Example 6
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 7
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 8
Source File: Util.java    From polling-station-app with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Sets up a top-padding for the given app bar equal to the height of the status bar.
 * This increases the length of the app bar so it fits nicely below the status bar.
 * This method also sets the status bar transparency.
 *
 * @param appBar   Toolbar to set padding to
 * @param activity Activity - current activity
 */
public static void setupAppBar(Toolbar appBar, Activity activity) {
    appBar.setPadding(0, getStatusBarHeight(activity.getResources()), 0, 0);

    SystemBarTintManager tintManager = new SystemBarTintManager(activity);
    tintManager.setStatusBarTintEnabled(true);
    tintManager.setNavigationBarTintEnabled(true);
    tintManager.setTintColor(Color.parseColor("#10000000"));
}
 
Example 9
Source File: QRCodeScannerActivity.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        getWindow().getDecorView()
                .setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qrcode_scanner);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
//        upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
//        getSupportActionBar().setHomeAsUpIndicator(upArrow);
        toolbar.getNavigationIcon().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
        toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + getStatusBarHeight(), toolbar.getPaddingRight(), toolbar.getPaddingBottom());
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        mQRCodeReader = (QRCodeReaderView) findViewById(R.id.qr_decoder);

        mQRCodeReader.setAutofocusInterval(2000L);
        mQRCodeReader.setOnQRCodeReadListener(this);
        mQRCodeReader.setBackCamera();
        mQRCodeReader.startCamera();
    }
 
Example 10
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 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: 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);
                }
            });
}
 
Example 13
Source File: PictureActivity.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picture);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setTitle(R.string.media_picture);

    int statbarHeight = Screen.getStatusBarHeight();
    if (Build.VERSION.SDK_INT >= 19) {
        toolbar.setPadding(0, statbarHeight, 0, 0);
    }

    final Bundle bundle = getIntent().getExtras();
    path = bundle.getString(ARG_FILE_PATH);
    int sender = bundle.getInt(ARG_OWNER, 0);

    toolbar.setVisibility(View.GONE);

    transitionTop = bundle.getInt(ARG_IMAGE_TOP, 0);
    transitionLeft = bundle.getInt(ARG_IMAGE_LEFT, 0);
    transitionWidth = bundle.getInt(ARG_IMAGE_WIDTH, 0);
    transitionHeight = bundle.getInt(ARG_IMAGE_HEIGHT, 0);

    transitionView = (ImageView) findViewById(R.id.transition);
    backgroundView = findViewById(R.id.background);
    containerView = findViewById(R.id.container);
    containerView.setAlpha(0);
    fragment = new PictureFragment();
    fragment.setArguments(bundle);
    getSupportFragmentManager().beginTransaction()
            .add(R.id.container, fragment)
            .commit();


    Bitmap bitmap = null;
    try {
        bitmap = ImageLoading.loadBitmapOptimized(path);
        bitmapWidth = bitmap.getWidth();
        bitmapHeight = bitmap.getHeight();
    } catch (ImageLoadException e) {
        e.printStackTrace();
        return;
    }
    transitionView.setImageBitmap(bitmap);
    if (bitmap != null)
        bitmap = null;

    MediaFullscreenAnimationUtils.animateForward(transitionView, bitmapWidth, bitmapHeight, transitionLeft, transitionTop, transitionWidth, transitionHeight,
            new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    containerView.setAlpha(1);
                    transitionView.setAlpha(0f);
                }
            });
    MediaFullscreenAnimationUtils.animateBackgroundForward(backgroundView, null);
}
 
Example 14
Source File: MainWindow.java    From FancyPlaces with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main_window);

    curAppContext = (FancyPlacesApplication) getApplicationContext();

    setDefaultTitle();

    // inflate toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.main_window_toolbar);
    setSupportActionBar(toolbar);
    if (Build.VERSION.SDK_INT >= 19)
    {
        int padding_right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
        toolbar.setPadding(toolbar.getPaddingLeft(), curAppContext.getStatusBarHeight(), padding_right, 0);
    }

    // store data
    fancyPlacesDatabase = new FancyPlacesDatabase(getApplicationContext());
    fancyPlacesDatabase.open();
    fancyPlaces = (ArrayList<FancyPlace>) fancyPlacesDatabase.getAllFancyPlaces();
    fancyPlaceArrayAdapter = new FancyPlacesArrayAdapter(getApplicationContext(), R.layout.list_item_fancy_place, fancyPlaces);

    ImageFile.curAppContext = curAppContext;

    // viewpager
    viewpagerAdapter = new MainWindowViewpagerAdapter(getApplicationContext(), getSupportFragmentManager(), createTabList());
    pager = (ViewPager) findViewById(R.id.main_window_viewpager);
    pager.setAdapter(viewpagerAdapter);

    // Asiging the Sliding Tab Layout View
    tabs = (SlidingTabLayout) findViewById(R.id.main_window_tabs);
    tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

    // Setting Custom Color for the Scroll bar indicator of the Tab View
    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.tabsScrollColor);
        }
    });

    // Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);

    // set current menu
    curState.curMenu = R.menu.menu_main_window;

    // check if we got called through an intent
    Uri u = getIntent().getData();
    if (u != null)
        loadFromFile(u.getPath());
}