Last active
August 29, 2015 14:18
-
-
Save dnkm/05957538301d0445692a to your computer and use it in GitHub Desktop.
Android Tutorial Chapter 2 - Action Bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Specify actions in XML --> | |
<!-- res/menu/main_activity_actions.xml --> | |
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:id="@+id/action_search" | |
android:icon="@drawable/ic_action_search" | |
android:title="@string/action_search" | |
android:showAsAction="ifRoom" /> <!-- appear as action button if there is room, otherwise in the overflow --> | |
<item android:id="@+id/action_settings" | |
android:title="@string/action_settings" | |
android:showAsAction="never" /> <!-- only appear in the overflow --> | |
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
case R.id.action_search: | |
openSearch(); | |
return true; | |
case R.id.action_settings: | |
openSettings(); | |
return true; | |
default: | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment