博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LearnMenu
阅读量:4880 次
发布时间:2019-06-11

本文共 2657 字,大约阅读时间需要 8 分钟。

================================

Download project link : http://pan.baidu.com/netdisk/singlepublic?fid=1024867_1008262409

included files are:

LearnMenu.apk

LearnMenu.zip
result_1.png
result_2.png
result_3.png

================================

 

package edu.cquptzx.LearnMenu;

 

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.Toast;

 

publicclass LearnMenuActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    publicvoid onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);      

    }

   

    /*Createt the optionsMenu.

     *

     * public abstract MenuItem add (int groupId, int itemId, int order, CharSequence title)

     * Add a new item to the menu. This item displays the given title for its label.

      * groupId :  The group identifier that this item should be part of. This can be used to define groups of items for batch state changes. Normally use NONE if an item should not be in a group.

       itemId: Unique item ID. Use NONE if you do not need a unique ID.

       order  : The order for the item. Use NONE if you do not care about the order. See getOrder().

       title  : The text to display for the item.

        Returns  :   The newly added menu item.*

     * */

    @Override

    publicboolean onCreateOptionsMenu(Menu menu)

    {

       menu.add(0,0,0,R.string.app_about);

       menu.add(0,1,1,R.string.app_exit);

       returnsuper.onCreateOptionsMenu(menu);

    }

   

    @Override

    publicboolean onOptionsItemSelected(MenuItem item)

    {

       switch(item.getItemId())

       {

       case 0:

           openOptionsDialog_About();

           break;

       case 1:

           openOptionsDialog_Exit();

           break;

       default:

           break;       

       }

       returnsuper.onOptionsItemSelected(item);

    }

   

   

    privatevoid openOptionsDialog_About()

    {

       new AlertDialog.Builder(this)

       .setTitle(R.string.app_about)

       .setMessage(R.string.app_message)

       .setPositiveButton(

              R.string.app_ok,

              new DialogInterface.OnClickListener()

              {

                  @Override

                  publicvoid onClick(DialogInterface dialog, int which) {

                    

                  }                

              }

              )

       .show();

    }

   

    privatevoid openOptionsDialog_Exit()

    {

       new AlertDialog.Builder(this)

       .setTitle(R.string.app_exitAlarm)

       .setPositiveButton(

              R.string.app_ok,

              new DialogInterface.OnClickListener()

              {

                  @Override

                  publicvoid onClick(DialogInterface dialog, int which) {

                     finish();

                  }                

              }

              )

       .setNegativeButton(

              R.string.app_exit_cancle,

              new DialogInterface.OnClickListener()

              {

                  @Override

                  publicvoid onClick(DialogInterface dialog, int which) {

           Toast.makeText(getBaseContext(), "Welcome Back ",Toast.LENGTH_SHORT).show();

                  }                

              })

       .show();

    }

}

 

result_3

 

 

 

 

 

For more questions , contacts me by :

or 

转载于:https://www.cnblogs.com/xilifeng/archive/2012/08/11/2633790.html

你可能感兴趣的文章
题解报告:hdu 1087 Super Jumping! Jumping! Jumping!
查看>>
汇编实验一
查看>>
2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
查看>>
HDU 4856 Tunnels
查看>>
常用的页面加载慢的解决方案
查看>>
Excel催化剂开源第11波-动态数组函数技术开源及要点讲述
查看>>
php设计模式课程---9、桥接模式是什么
查看>>
thinkphp5.0的验证码安装和相关错误
查看>>
第二百七十六节,MySQL数据库,【显示、创建、选定、删除数据库】,【用户管理、对用户增删改查以及授权】...
查看>>
第一百八十六节,jQuery,验证表单插件,Ajax 表单插件,验证和提交表单
查看>>
HDU 6351 Beautiful Now(DFS)多校题解
查看>>
Centos-bzip2压缩文件-bzip2 bunzip2
查看>>
集合00_Java集合框架
查看>>
百度lbs学习
查看>>
centos里启用snmp的监控
查看>>
第四节:tensorflow图的基本操作
查看>>
【详●析】危险路径
查看>>
二叉树中和为某一值的所有路径
查看>>
Struts2学习第五课 通过和ServletAPI耦合的方式获取WEB资源
查看>>
sns 基于校园的社交网络服务(三版-1期)小结部分问题
查看>>