compatible Action Bar to your application, targeting Android v2.1+ Designed to mirror the Action Bar API found in later platforms, as closely as possible
added via the menu: <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_search" android:title="@string/menu_search" android:actionViewClass="android.widget.SearchView" android:showAsAction="always" /> <!-- Your other items... --> </menu>
added via the menu: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yourapp="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/menu_search" android:title="@string/menu_search" yourapp:actionViewClass="android.support.v7.widget.SearchView" yourapp:showAsAction="always" /> <!-- Your other items... --> </menu>
element in AndroidManifest.xml <activity android:name=".YourActivity" android:uiOptions="splitActionBarWhenNarrow"> <intent-filter> ... </intent-filter> <meta-data android:name="android.support.UI_OPTIONS" android:value="splitActionBarWhenNarrow" /> </activity> API v14+ API v7+
{ // Inflate the menu getMenuInflater().inflate(R.menu.main_menu, menu); // Find the share item MenuItem shareItem = menu.findItem(R.id.menu_share); // Retrieve the SearchView mShareAp = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem); return super.onCreateOptionsMenu(menu); } // Later when you have created a share intent mShareAp.setShareIntent(shareIntentForContent);
it the clicked view for an anchor PopupMenu popup = new PopupMenu(getActivity(), view); // Inflate our menu resource into the PopupMenu's Menu popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu()); // Set a listener so we are notified if a menu item is clicked popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { ... } }); // Finally show the PopupMenu popup.show();
using ActionBarActivity // Enable Home button and set to display as up navigation getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Create ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); // Finally set the ActionBarDrawerToggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle);
// Needs to be called before setting the content view supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Now set the content view setContentView(R.layout.activity_main); } // When ready, show the indeterminate progress bar setSupportProgressBarIndeterminateVisibility(true);
AndroidManifest.xml: In your Activity: // Display home item as up navigation getSupportActionBar().setDisplayHomeAsUpEnabled(true); <activity android:name=".YourActivity" android:parentActivityName=".YourParentActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".YourParentActivity" /> </activity> API v16+ API v7+