sample_menu.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_search" android:icon="@android:drawable/ic_menu_search" android:showAsAction="always" android:title="検索"/> </menu> |
Activity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
@Override public boolean onCreateOptionsMenu(Menu menu){ MenuInflater inflater = getMenuInflater(); inflater .inflate(R.menu.sample_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item){ switch(item.getItemId()){ case R.id.menu_search: //検索 search(); return true; default: return super.onOptionsItemSelected(item); } } |