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

The following examples show how to use android.support.v7.app.ActionBar#setDisplayOptions() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: QueryHighlighter   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAdapter = new CheesesAdapter();

    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(mAdapter);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.search_view);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    final EditText editText = (EditText) actionBar.getCustomView();
    editText.addTextChangedListener(mTextWatcher);
    editText.requestFocus();
}
 
Example 2
public void setActionBarLayout(int layoutId, Context mContext) {
    ActionBar actionBar = getSupportActionBar();
    if (null != actionBar) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(layoutId, new LinearLayout(mContext), false);
        ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        actionBar.setCustomView(v, layout);
        media_net = (Button)findViewById(R.id.media_network);
        media_history = (Button)findViewById(R.id.media_history);
        media_setting = (Button)findViewById(R.id.media_setting);
        media_net.setOnClickListener(this);
        media_setting.setOnClickListener(this);
        media_history.setOnClickListener(this);
    }else{
        Toast.makeText(MainActivity.this, "ActionBar不存在", Toast.LENGTH_SHORT).show();
    }

}
 
Example 3
public void setActionBarLayout(int layoutId, Context mContext) {
    ActionBar actionBar = getSupportActionBar();
    if (null != actionBar) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(layoutId, new LinearLayout(mContext), false);
        ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        actionBar.setCustomView(v, layout);

        netHistory = (Button) findViewById(R.id.net_history);
        netScan = (Button) findViewById(R.id.net_scan);
        netSetting = (Button) findViewById(R.id.net_setting);
        netScan.setOnClickListener(this);
        netHistory.setOnClickListener(this);
        netSetting.setOnClickListener(this);

    }else{
        Toast.makeText(NetMediaActivty.this, "ActionBar不存在", Toast.LENGTH_SHORT).show();
    }

}
 
Example 4
Source Project: SpecialAlarmClock   File: BaseActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.middle_title_actionbar);

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }
}
 
Example 5
Source Project: android-weather   File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (getSupportActionBar() != null) {
            ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayShowHomeEnabled(false);
            View mActionBarView = getLayoutInflater().inflate(R.layout.main_action_bar, null);
            actionBar.setCustomView(mActionBarView);
            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        }

        mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
//        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MAX_TIME,
//                MAX_DISTANCE, mLocationListener);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new TenDayForecastFragment())
                    .commit();
        }
    }
 
Example 6
Source Project: KA27   File: RecyclerViewFragment.java    License: Apache License 2.0 5 votes vote down vote up
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
        ContextCompat.getColor(getActivity(), android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}
 
Example 7
@Override
public void setSupportActionBar(@Nullable final Toolbar toolbar) {
    super.setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 8
private void initActionBar() {
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 9
private void initActionBar() {
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 10
@Override
public void setSupportActionBar(@Nullable final Toolbar toolbar) {
    super.setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 11
@Override
public void setSupportActionBar(@Nullable final Toolbar toolbar) {
    super.setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 12
@Override
public void setSupportActionBar(@Nullable final Toolbar toolbar) {
    super.setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 13
@Override
public void setSupportActionBar(@Nullable final Toolbar toolbar) {
    super.setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_HOME_AS_UP);
    }
}
 
Example 14
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
            getResources().getColor(android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}
 
Example 15
Source Project: V.FlyoutTest   File: ActionBarTabs.java    License: MIT License 5 votes vote down vote up
public void onToggleTabs(View v) {
    final ActionBar bar = getSupportActionBar();

    if (bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS) {
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    } else {
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    }
}
 
Example 16
Source Project: Anagram-Solver   File: AnagramFragment.java    License: MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ActionBar actionbar = ((MainActivity) getActivity()).getSupportActionBar();
    actionbar.show();
    actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionbar.setCustomView(R.layout.actionbar_view);
}
 
Example 17
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

       setContentView(R.layout.preference_activity);
       Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
       setSupportActionBar(toolbar);

       ActionBar ab = getSupportActionBar();
       if (ab != null) {
           ab.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
       }
}
 
Example 18
public static void configureFlatBlueActionBar(Context context, ActionBar actionBar) {
    setThemedActionBarDrawable(context, actionBar);
    actionBar.setDisplayOptions(14, 14);
}
 
Example 19
Source Project: V.FlyoutTest   File: ActionBarDisplayOptions.java    License: 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);
}