Java Code Examples for android.support.v7.app.ActionBar#getDisplayOptions()

The following examples show how to use android.support.v7.app.ActionBar#getDisplayOptions() . 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: ActivityBase.java    From Ansole with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final ActionBar ab = getSupportActionBar();
    if (item.getItemId() == android.R.id.home && ab != null &&
            (ab.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
        finish();
    }
    return super.onOptionsItemSelected(item);
}
 
Example 2
Source File: ActionBarDisplayOptions.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    final ActionBar bar = getSupportActionBar();
    int flags = 0;
    switch (v.getId()) {
        case R.id.toggle_home_as_up:
            flags = ActionBar.DISPLAY_HOME_AS_UP;
            break;
        case R.id.toggle_show_home:
            flags = ActionBar.DISPLAY_SHOW_HOME;
            break;
        case R.id.toggle_use_logo:
            flags = ActionBar.DISPLAY_USE_LOGO;
            break;
        case R.id.toggle_show_title:
            flags = ActionBar.DISPLAY_SHOW_TITLE;
            break;
        case R.id.toggle_show_custom:
            flags = ActionBar.DISPLAY_SHOW_CUSTOM;
            break;
        case R.id.toggle_navigation:
            bar.setNavigationMode(
                    bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD
                            ? ActionBar.NAVIGATION_MODE_TABS
                            : ActionBar.NAVIGATION_MODE_STANDARD);
            return;
        case R.id.cycle_custom_gravity: {
            ActionBar.LayoutParams lp = mCustomViewLayoutParams;
            int newGravity = 0;
            switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.LEFT:
                    newGravity = Gravity.CENTER_HORIZONTAL;
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    newGravity = Gravity.RIGHT;
                    break;
                case Gravity.RIGHT:
                    newGravity = Gravity.LEFT;
                    break;
            }
            lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity;
            bar.setCustomView(mCustomView, lp);
            return;
        }
        case R.id.toggle_visibility:
            if (bar.isShowing()) {
                bar.hide();
            } else {
                bar.show();
            }
            return;
    }

    int change = bar.getDisplayOptions() ^ flags;
    bar.setDisplayOptions(change, flags);
}