<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_settings" android:orderInCategory="100" android:showAsAction="never" android:title="@string/action_settings"/> </menu>
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflator = getSupportMenuInflater(); inflator.inflate(R.menu.default_style, menu); return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab_style); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); Tab tab1 = actionBar.newTab(); tab1.setText("Tab 1"); tab1.setTabListener(this); actionBar.addTab(tab1); Tab tab2 = actionBar.newTab(); tab2.setText("Tab 2"); tab2.setTabListener(this); actionBar.addTab(tab2); Tab tab3 = actionBar.newTab(); tab3.setText("Tab 3"); tab3.setTabListener(this); actionBar.addTab(tab3); } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { Toast.makeText(this, "change:" + tab.getPosition(), Toast.LENGTH_SHORT).show(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list_style); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); for (int i = 1; i <= 5; i++) { adapter.add("item" + i); } actionBar.setListNavigationCallbacks(adapter, new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { Toast.makeText(ListStyleActivity.this, "pos" + itemPosition, Toast.LENGTH_SHORT).show(); return false; } }); }