Android CreateOptionsMenu
<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>
@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); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。