2012-10-26 48 views
4

enter image description here我注意到,在我的應用程序中,當我爲不具有硬件菜單按鈕的新設備添加菜單時,它將三個點添加到操作欄。但是,我發現在某些應用程序中,實際上可以將這三個點移動到底部(在軟件導航上) 這怎麼實現?我也使用actionbarsherlock,如果這有所作爲。操作欄中的三點動作溢出菜單?

+0

這是相當模糊可以詳細說明你正在建造什麼應用程序菜單? – Akyl

+0

菜單按鈕。我會附上一張照片。 – HAxxor

+0

你的意思是ActionBars [像這些](http://developer.android.com/design/media/action_bar_pattern_rotation.png),特別是在左前方? – Sam

回答

7

您可以通過將targetSdk設置爲14以下來實現此目的。我說「實現」,因爲這是不好的做法。對於具有軟件按鍵的設備,只要您在ActionBar中使用主題,它就會在ActionBar上顯示菜單。如果您使用的是沒有ActionBar(非Holo)的主題,則會顯示三個點。

這三個點是討厭的。
這三個點是邪惡的。
三個點必須。是。根除。

總之,我會避免它。 :)

參見:Menu Button of Shame

+0

謝謝。是的,如果我把目標sdk放在14以下,它會打破很多東西。韋爾普......這很糟糕。猜猜我不會走這條路。哈哈。感謝你的回答。 – HAxxor

+0

沒問題。 :)爲什麼它吸?只是好奇,你的目標是什麼?你爲什麼想要他們在底部? – kcoppock

+0

說實話,我猜測他是在做一個遊戲。因爲3個按鈕看起來分散注意力。 – Akyl

1

所以,原來這是很簡單的,我最近在我的應用程序來實現。

需要在溢出菜單中顯示其嵌套一個菜單項下如下的項目:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:id="@+id/empty" 
     android:orderInCategory="101" 
     android:showAsAction="always" 
     android:icon="@drawable/ic_action_overflow"> 

     <menu>   

      <item 
       android:id="@+id/action_settings" 
       android:orderInCategory="96" 
       android:showAsAction="never" 
       android:title="@string/menu_settings" 
       android:icon="@drawable/ic_action_settings"/> 

      <item 
       android:id="@+id/action_share" 
       android:orderInCategory="97" 
       android:showAsAction="never" 
       android:title="@string/menu_share" 
       android:icon="@drawable/ic_action_share"/> 

      <item 
       android:id="@+id/action_rate" 
       android:orderInCategory="98" 
       android:showAsAction="never" 
       android:title="@string/menu_rate" 
       android:icon="@drawable/ic_action_important"/> 

      <item 
       android:id="@+id/action_feedback" 
       android:orderInCategory="99" 
       android:showAsAction="never" 
       android:title="@string/menu_feedback" 
       android:icon="@drawable/ic_action_edit"/> 

      </menu>   
     </item> 
</menu> 

現在,編輯如下主要活動文件:

package com.example.test; 
//all your import statements go here 

Menu mainMenu=null; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); } 

@Override 
public boolean onCreateOptionsMenu(Menu menu) {  
// Inflate the menu; this adds items to the action bar if it is present. 
getMenuInflater().inflate(R.menu.main, menu); 
mainMenu=menu; 
return true; } 


//Menu press should open 3 dot menu 
@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if (keyCode==KeyEvent.KEYCODE_MENU) { 
     mainMenu.performIdentifierAction(R.id.empty, 0); 
     return true; } 
    return super.onKeyDown(keyCode, event); }