最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android創(chuàng)建optionsmenu的方法

 更新時(shí)間:2015年07月15日 10:32:47   作者:craigyang  
這篇文章主要介紹了android創(chuàng)建optionsmenu的方法,實(shí)例分析了Android菜單項(xiàng)的設(shè)置與創(chuàng)建技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了android創(chuàng)建optionsmenu的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

一、用xml配置

在res文件夾下新建menu文件夾,menu下新建options_menu.xml文件,加入代碼

1、

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/about"
android:title="關(guān)于"
android:checkable="true" />
<item android:id="@+id/choose"
android:title="選擇" />
<item android:id="@+id/quit"
android:title="QUIT" />
</menu>

2、activity類中加入代碼

public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater inflater = getMenuInflater();
 inflater.inflate(R.menu.options_menu, menu);
 return super.onCreateOptionsMenu(menu);
 }
 public boolean onOptionsItemSelected(MenuItem aitem)
 {
 super.onOptionsItemSelected(aitem);
 switch(aitem.getItemId())
 {
 case R.id.about:
 setTitle("你按下了'關(guān)于'菜單項(xiàng)");
 progressBarHorizontal.setProgress(200);
 openOptionsDialog();
 break;
 case R.id.choose:
 setTitle("你按下了'選擇'菜單項(xiàng)");
 openOptionsChooseDialog();
 break;
 case R.id.quit:
 setTitle("你按下了'離開'菜單項(xiàng)");
 finish();
 break;
 }
 return true;
 }
 private void openOptionsDialog()
 {
 new AlertDialog.Builder(this)
 .setTitle(R.string.app_about)
 .setMessage(R.string.app_about_msg)
 .setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener()
 {
 public void onClick(DialogInterface dialoginterface, int i)
 {
 }
 })
 .show();
 }
 private void openOptionsChooseDialog()
 {
 new AlertDialog.Builder(this)
 .setTitle(R.string.str_alert)
 .setItems(R.array.items_irdc_dialog, new DialogInterface.OnClickListener()
 {
 public void onClick(DialogInterface dialoginterface, int i)
 {/*
 String[] aryShop = getResources().getStringArray(R.array.items_irdc_dialog);
 new AlertDialog.Builder(this)
 .setMessage(R.string.app_about_msg)
 .setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener()
 {
 public void onClick(DialogInterface dialoginterface, int i)
 {
 }
 })
 .show();*/
 }
 })
 .show();
}

OK。。。

二、直接上代碼:

public static final int ABOUT_ID = Menu.FIRST;
public static final int CHOOSE_ID = Menu.FIRST + 1;
public static final int EXIT_ID = Menu.FIRST + 2;
public boolean onCreateOptionsMenu(Menu menu)
{
 menu.add(0, ABOUT_ID, 0, R.string.app_about);
 menu.add(0, CHOOSE_ID, 0, R.string.str_choose);
 menu.add(0, EXIT_ID, 0, R.string.str_exit);
 return super.onCreateOptionsMenu(menu);
 }
 public boolean onOptionsItemSelected(MenuItem aitem)
 {
 super.onOptionsItemSelected(aitem);
 switch(aitem.getItemId())
 {
 case ABOUT_ID:
 setTitle("你按下了'關(guān)于'菜單項(xiàng)");
 progressBarHorizontal.setProgress(200);
 openOptionsDialog();
 break;
 case CHOOSE_ID:
 setTitle("你按下了'選擇'菜單項(xiàng)");
 openOptionsChooseDialog();
 break;
 case EXIT_ID:
 setTitle("你按下了'離開'菜單項(xiàng)");
 finish();
 break;
 }
 return true;
 }
 private void openOptionsDialog()
 {
 new AlertDialog.Builder(this)
 .setTitle(R.string.app_about)
 .setMessage(R.string.app_about_msg)
 .setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener()
 {
 public void onClick(DialogInterface dialoginterface, int i)
 {
  
 }
 })
 .show();
 }
 private void openOptionsChooseDialog()
 {
 new AlertDialog.Builder(this)
 .setTitle(R.string.str_alert)
 .setItems(R.array.items_irdc_dialog, new DialogInterface.OnClickListener()
 {
 public void onClick(DialogInterface dialoginterface, int i)
 {/*
 String[] aryShop = getResources().getStringArray(R.array.items_irdc_dialog);
 new AlertDialog.Builder(this)
 .setMessage(R.string.app_about_msg)
 .setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener()
 {
 public void onClick(DialogInterface dialoginterface, int i)
 {
  
 }
 })
 .show();*/
 }
 })
 .show();
}

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

高唐县| 泗阳县| 大新县| 大同县| 太康县| 万全县| 资溪县| 连州市| 洮南市| 沅陵县| 个旧市| 彰武县| 叶城县| 东山县| 温宿县| 来凤县| 吴江市| 平顶山市| 岫岩| 巩留县| 微山县| 临桂县| 浑源县| 专栏| 珲春市| 南部县| 西充县| 扬州市| 石河子市| 察雅县| 泾源县| 芮城县| 赫章县| 鹤岗市| 当阳市| 始兴县| 封丘县| 清苑县| 烟台市| 扶沟县| 太湖县|