2012-07-16 92 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