Menu's Android
Menu's Android
COURSE OBJECTIVES
At the end of this lecture, each student should:
<item android:id="@+id/option_settings"
android:title="@string/settings" />
<item android:id="@+id/option_toast"
android:title="@string/toast" />
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
1. Create an XML menu resource file for the menu items, and assign appearance and
position attributes
2. Register a view to the context menu using the registerForContextMenu() method
of the Activity class.
3. Implement the onCreateContextMenu() method in your activity or fragment to
inflate the menu.
4. Implement the onContextItemSelected() method in your activity or fragment to
handle menu item clicks.
5. Create a method to perform an action for each context menu item.
MOBILE APPLICATION DEVELOPMENT 24
CONTEXTUAL ACTION
BAR- STEPS
1. Create XML menu resource
file and assign icons for items
2. setOnLongClickListener()
on view that triggers the
contextual action
bar and call
startActionMode() to
handle click