Android ActionBar And Menu
menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.buzz.javatest.SecondActivity"> <item android:id="@+id/action_syncSysCfg" android:title="@string/syncSystemConfig" android:orderInCategory="100" app:showAsAction="never"/> <item android:id="@+id/action_voicePlayLang" android:title="@string/voicePlayLanguage" android:orderInCategory="200" app:showAsAction="never"> <menu> <item android:id="@+id/action_langSC" android:icon="@android:drawable/ic_btn_speak_now" android:title="@string/langSC" /> <item android:id="@+id/action_langCC" android:icon="@android:drawable/ic_btn_speak_now" android:title="@string/langCC" /> <item android:id="@+id/action_langEN" android:icon="@android:drawable/ic_btn_speak_now" android:title="@string/langEN" /> <item android:id="@+id/action_langPT" android:icon="@android:drawable/ic_btn_speak_now" android:title="@string/langPT" /> </menu> </item> </menu>
activity
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement switch (id) { case R.id.action_syncSysCfg: Toast.makeText(this, "系统设置同步完成", Toast.LENGTH_SHORT).show(); break; case R.id.action_langCC: Toast.makeText(this, "当前选择为粤语播放", Toast.LENGTH_SHORT).show(); break; case R.id.action_langSC: Toast.makeText(this, "当前选择为普通话播放", Toast.LENGTH_SHORT).show(); break; case R.id.action_langPT: Toast.makeText(this, "当前选择为葡语播放", Toast.LENGTH_SHORT).show(); break; case R.id.action_langEN: Toast.makeText(this, "当前选择为英语播放", Toast.LENGTH_SHORT).show(); break; } return super.onOptionsItemSelected(item); }
Ref:Android ActionBar与Menu - 1 - api demos 学习