2012-07-16 86 views
0

我在我的活動中有ActionBarSherlock操作欄。它使用方法onCreateOptionsMenu(菜單菜單)創建。如何讓這個菜單像操作欄一樣可用並用一些按鈕創建普通菜單?Android使用ActionBarSherlock創建普通菜單

+0

你的意思是,如何強制菜單按鈕是在動作條上2.3〜Android版本? – schwiz 2012-07-16 17:47:47

+0

我的意思是創建普通菜單(與菜單按鈕一起調用)以及ActionBarSherlock – Stas 2012-07-17 07:02:33

+0

它應該已經在老版本的android上執行了。爲了在新版本上做到這一點,以及針對比honeycomb更早的目標sdk進行編譯。 – schwiz 2012-07-17 17:15:15

回答

0

爲您的應用程序創建佈局。例如,爲您的菜單創建一個按鈕。你也可以使用圖形UI UI eclipse插件來定位它。

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/testButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:text="@string/testTitle"/> 
</RelativeLayout> 

在您的活動類,它擴展com.android.Activity,

Button testButton; 

testButton = (Button) findViewById(R.id.testButton); 

     testButton .setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
      // Code to perform on click of the menu button 
      } 
     }); 
+0

問題不在於如何創建一個簡單的按鈕。 – Stas 2012-07-16 12:13:30