首页 > 移动平台 > 详细

Android CreateOptionsMenu

时间:2015-03-13 17:56:29      阅读:522      评论:0      收藏:0      [点我收藏+]
<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);
    }

 Ref:Android ActionBar 一步一步分析

 Ref:Android ActionBar与Menu - 1 - api demos 学习

Android CreateOptionsMenu

原文:http://www.cnblogs.com/ncore/p/4335421.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!