亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android中menu使用詳解

 更新時間:2017年10月19日 15:40:27   作者:dandan君  
本文通過實例代碼給大家分享android中menu的使用,感興趣的朋友一起看看吧

Menu(菜單)是Android中一定會使用的模塊,每個Android項目都會用到Menu來給用戶起到選擇和導航的作用,提升用戶體驗,下面通過本文給大家分享android 中menu使用,需要的朋友一起看看吧

很多activity界面中都存在一個菜單欄,就是點擊右上角的一個按鈕的時候會出現(xiàn)一個下拉列表差不多的東西,這個功能的實現(xiàn)其實只需要下面的兩步,每一個activity都可以擁有自己獨一無二的menu,具體的格式可以自己進行定義,詳細的創(chuàng)建步驟如下

①在res下的menu中創(chuàng)建file_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
  <item
    android:icon="@drawable/ic_launcher"
    android:title="File">
    <menu>
      <group android:id="@+id/noncheckable_group" >
        <item
          android:id="@+id/newFile"
          android:alphabeticShortcut="n"
          android:title="New"/>
        <item
          android:id="@+id/openFile"
          android:alphabeticShortcut="o"
          android:title="Open"/>
        <item
          android:id="@+id/saveFile"
          android:alphabeticShortcut="s"
          android:title="Save"/>
      </group>
    </menu>
  </item>
</menu>

②Java代碼:

// 創(chuàng)建Menu
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    mi.inflate(R.menu.file_menu, menu);
    return true;
  }
  // Menu的點擊事件
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.newFile:
      Toast.makeText(Menu_Resource.this, "點擊了newFile", 800).show();
      break;
    case R.id.openFile:
      Toast.makeText(Menu_Resource.this, "點擊了openFile", 800).show();
      break;
    case R.id.saveFile:
      Toast.makeText(Menu_Resource.this, "點擊了saveFile", 800).show();
      break;
    }
    return true;
  }
  //onCreateOptionsMenu和onOptionsItemSelected方法為Acitivity中的

總結

以上所述是小編給大家介紹的Android中menu使用詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

最新評論