zoukankan      html  css  js  c++  java
  • LearnMenu

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

    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_1 

    result_2

    result_3

    For more questions , contacts me by :

    cquptzx@qq.com or  cquptzx@outlook.com

  • 相关阅读:
    js json字符串与json对象互相转换(最全)
    eclipse 离线安装SVN插件(支持eclipse201909)
    eclipse maven项目如何将所有的jar包复制到lib目录下?
    windows/tomcat 修改java虚拟机JVM以utf-8字符集加载class文件的两种方式
    eclipse 设置所有文件编码为UTF-8(最全)
    控制程序的启动数量(限制游戏多开)
    POJ 1719 Shooting Contest(二分图匹配)
    微信企业号开发:消息类型与差别
    Android
    SSI(Server Side Include)简单介绍
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2633790.html
Copyright © 2011-2022 走看看