2013-05-21 96 views
0

我試圖讓我的選項的菜單圖標通常出現在我平板電腦屏幕的一角。它不在那裏!我目前正在使用Android 4.2.2進行開發。下面是我使用當前的Java代碼:我假設它有毛病我的Java代碼選項菜單圖標沒有出現在平板電腦上

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

<item 
    android:id="@+id/menu_loggermap_tracking" 
    android:alphabeticShortcut="t" 
    android:icon="@drawable/ic_menu_movie" 
    android:showAsAction="ifRoom" 
    android:title="@string/menu_tracking"/> 
<item 
    android:id="@+id/menu_loggermap_layers" 
    android:alphabeticShortcut="l" 
    android:icon="@drawable/ic_menu_mapmode" 
    android:showAsAction="ifRoom" 
    android:title="@string/menu_showLayers"/> 
<item 
    android:id="@+id/menu_loggermap_note" 
    android:alphabeticShortcut="n" 
    android:icon="@drawable/ic_menu_myplaces" 
    android:showAsAction="ifRoom" 
    android:title="@string/menu_insertnote"/> 
<item 
    android:id="@+id/menu_loggermap_stats" 
    android:alphabeticShortcut="s" 
    android:icon="@drawable/ic_menu_picture" 
    android:showAsAction="ifRoom" 
    android:title="@string/menu_statistics"/> 
<item 
    android:id="@+id/menu_loggermap_share" 
    android:alphabeticShortcut="i" 
    android:icon="@drawable/ic_menu_share" 
    android:showAsAction="ifRoom" 
    android:title="@string/menu_shareTrack"/> 
<item 
    android:id="@+id/menu_loggermap_tracklist" 
    android:alphabeticShortcut="p" 
    android:icon="@drawable/ic_menu_show_list" 
    android:showAsAction="collapseActionView" 
    android:title="@string/menu_tracklist"/> 
<item 
    android:id="@+id/menu_loggermap_settings" 
    android:alphabeticShortcut="c" 
    android:icon="@drawable/ic_menu_preferences" 
    android:showAsAction="collapseActionView" 
    android:title="@string/menu_settings"/> 
<item 
    android:id="@+id/menu_loggermap_about" 
    android:alphabeticShortcut="a" 
    android:icon="@drawable/ic_menu_info_details" 
    android:showAsAction="collapseActionView" 
    android:title="@string/menu_about"/> 
<item 
    android:id="@+id/menu_loggermap_contrib" 
    android:alphabeticShortcut="o" 
    android:icon="@drawable/ic_menu_allfriends" 
    android:showAsAction="collapseActionView" 
    android:title="@string/menu_contrib"/> 
</menu> 

@Override 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     boolean result = super.onCreateOptionsMenu(menu); 

     //theMenu = menu; 
     //new MenuInflater(getApplication()).inflate(R.menu.loggermap, menu); 

     menu.add(ContextMenu.NONE, MENU_TRACKING, ContextMenu.NONE, R.string.menu_tracking).setIcon(R.drawable.ic_menu_movie).setAlphabeticShortcut('T'); 
     menu.add(ContextMenu.NONE, MENU_LAYERS, ContextMenu.NONE, R.string.menu_showLayers).setIcon(R.drawable.ic_menu_mapmode).setAlphabeticShortcut('L'); 
     menu.add(ContextMenu.NONE, MENU_NOTE, ContextMenu.NONE, R.string.menu_insertnote).setIcon(R.drawable.ic_menu_myplaces); 

     menu.add(ContextMenu.NONE, MENU_STATS, ContextMenu.NONE, R.string.menu_statistics).setIcon(R.drawable.ic_menu_picture).setAlphabeticShortcut('S'); 
     menu.add(ContextMenu.NONE, MENU_SHARE, ContextMenu.NONE, R.string.menu_shareTrack).setIcon(R.drawable.ic_menu_share).setAlphabeticShortcut('I'); 

     menu.add(ContextMenu.NONE, MENU_TRACKLIST, ContextMenu.NONE, R.string.menu_tracklist).setIcon(R.drawable.ic_menu_show_list).setAlphabeticShortcut('P'); 
     menu.add(ContextMenu.NONE, MENU_SETTINGS, ContextMenu.NONE, R.string.menu_settings).setIcon(R.drawable.ic_menu_preferences).setAlphabeticShortcut('C'); 

     MenuItem noteMenu = menu.findItem(MENU_NOTE); 
     noteMenu.setEnabled(true); 

     return result; 
     //return (super.onCreateOptionsMenu(menu)); 
    } 

    /* 
    * (non-Javadoc) 
    * @see android.app.Activity#onPrepareOptionsMenu(android.view.Menu) 
    */ 
    @Override 
    public boolean onPrepareOptionsMenu(Menu menu) 
    { 
     MenuItem noteMenu = menu.findItem(MENU_NOTE); 
     noteMenu.setVisible(true); 
     //noteMenu.setEnabled(mLoggerServiceManager.isMediaPrepared()); 
     noteMenu.setEnabled(true); 

     MenuItem shareMenu = menu.findItem(MENU_SHARE); 
     shareMenu.setVisible(true); 
     //shareMenu.setEnabled(mTrackId >= 0); 
     shareMenu.setEnabled(true); 

     return super.onPrepareOptionsMenu(menu); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 
     boolean handled = false; 

     Uri trackUri; 
     Intent intent; 
     switch (item.getItemId()) 
     { 
     case MENU_TRACKING: 
      intent = new Intent(this, ControlTracking.class); 
      startActivityForResult(intent, MENU_TRACKING); 
      handled = true; 
      break; 
     case MENU_LAYERS: 
      showDialog(DIALOG_LAYERS); 
      handled = true; 
      break; 
     case MENU_NOTE: 
      /*intent = new Intent(this, InsertNote.class); 
      startActivityForResult(intent, MENU_NOTE);*/ 
      intent = new Intent(this, WaypointNewActivity.class); 
      startActivity(intent); 
      handled = true; 
      break; 
     case MENU_SETTINGS: 
      intent = new Intent(this, ApplicationPreferenceActivity.class); 
      startActivity(intent); 
      handled = true; 
      break; 
     case MENU_TRACKLIST: 
      intent = new Intent(this, TrackList.class); 
      intent.putExtra(Tracks._ID, this.mTrackId); 
      startActivityForResult(intent, MENU_TRACKLIST); 
      break; 
     case MENU_STATS: 
      if (this.mTrackId >= 0) 
      { 
       intent = new Intent(this, Statistics.class); 
       trackUri = ContentUris.withAppendedId(Tracks.CONTENT_URI, mTrackId); 
       intent.setData(trackUri); 
       startActivity(intent); 
       handled = true; 
       break; 
      } 
      else 
      { 
       showDialog(DIALOG_NOTRACK); 
      } 
      handled = true; 
      break; 
     case MENU_ABOUT: 
      intent = new Intent("org.openintents.action.SHOW_ABOUT_DIALOG"); 
      try 
      { 
       startActivityForResult(intent, MENU_ABOUT); 
      } 
      catch (ActivityNotFoundException e) 
      { 
       showDialog(DIALOG_INSTALL_ABOUT); 
      } 
      break; 
     case MENU_SHARE: 
      intent = new Intent(Intent.ACTION_RUN); 
      trackUri = ContentUris.withAppendedId(Tracks.CONTENT_URI, mTrackId); 
      intent.setDataAndType(trackUri, Tracks.CONTENT_ITEM_TYPE); 
      intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
      Bitmap bm = findViewById(R.id.mapScreen).getDrawingCache(); 
      if (bm != null) 
      { 
       Uri screenStreamUri = ShareTrack.storeScreenBitmap(bm); 
       intent.putExtra(Intent.EXTRA_STREAM, screenStreamUri); 
      } 
      startActivityForResult(Intent.createChooser(intent, getString(R.string.share_track)), MENU_SHARE); 
      handled = true; 
      break; 
     case MENU_CONTRIB: 
      showDialog(DIALOG_CONTRIB); 
     default: 
      handled = super.onOptionsItemSelected(item); 
      break; 
     } 
     return handled; 
    } 

的XML代碼是在這裏。我在這裏做錯了什麼?任何幫助,將不勝感激!

回答

0

您沒有指定您正在使用的平板電腦。如果平板電腦有硬件菜單按鈕 - 不適合的項目將在那裏。

我不明白你爲什麼要在代碼中創建的菜單,而不是隻充氣

@Override 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    super.onCreateOptionsMenu(menu); 
    getMenuInflater().inflate(R.menu.loggermap, menu); 
    return true; 
} 

而對於那些有項目的ActionView,加ifRoom太

android:showAsAction="ifRoom|collapseActionView" 
相關問題