首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

菜单旋钮,回退键,退出对话框

2012-08-29 
菜单按钮,回退键,退出对话框public boolean onCreateOptionsMenu(Menu menu){menu.add(0, 0, 0, 关于)m

菜单按钮,回退键,退出对话框

public boolean onCreateOptionsMenu(Menu menu){    menu.add(0, 0, 0, "关于");    menu.add(0, 1, 1, "退出");    return super.onCreateOptionsMenu(menu);        }    @Override    public boolean onOptionsItemSelected(MenuItem item) {    super.onOptionsItemSelected(item);    switch (item.getItemId()) {case 0:openAboutDialog();break;case 1:openQiutDialog();break;default:break;}    return true;    }        /**     * 关于     */    private void openAboutDialog(){    new AlertDialog.Builder(this).setTitle("关于").setMessage("这是关于的练习")    .setPositiveButton("确定", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which) {}}).show();    }        /**     * 退出     */    private void openQiutDialog(){    new AlertDialog.Builder(this).setTitle("退出").setMessage("你真的要退出吗?")    .setPositiveButton("退出", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which) {finish();}}).setNegativeButton("取消", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which) {}}).show();    }    /**     * 回退键提示     *      */    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        if(keyCode==KeyEvent.KEYCODE_BACK){        openQiutDialog();        }        return false;    }

热点排行