close
官方教學\
對res右鍵
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/new_game" android:icon="@mipmap/ic_launcher" android:title="按鈕1" /> <item android:id="@+id/help" android:icon="@mipmap/ic_launcher" android:title="按鈕2" /> </menu>
onCreate(Bundle savedInstanceState) 方法下
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.game_menu, menu);//R.menu.game_menu根據你所建立的menu變化名稱 return true; }
點擊事件
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.new_game: Log.i("mytest","1"); return true; case R.id.help: Log.i("mytest", "2"); return true; default: return super.onOptionsItemSelected(item); } }
全站熱搜
留言列表