1

我使用操作栏 sherlock 并在菜单中设置自定义布局:

<item
    android:id="@+id/action_menu"
    android:actionLayout="@layout/menu_item"
    android:icon="@drawable/b_menu"
    android:orderInCategory="1"
    android:showAsAction="always"/>
<item
    android:id="@+id/action_audio"
    android:actionLayout="@layout/audio_item"
    android:icon="@drawable/b_audio"
    android:orderInCategory="2"
    android:showAsAction="always"/>
<item
    android:id="@+id/action_mySong_details"
    android:actionLayout="@layout/my_song_properties"
    android:icon="@drawable/b_mysong"
    android:orderInCategory="2"
    android:showAsAction="always"/>

控制我使用的那些项目:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /** Create an option menu from res/menu/items.xml */
    getSherlock().getMenuInflater().inflate(R.menu.main_tab, menu);

    /** Get the action view of the menu item whose id is search */
    View v = (View) menu.findItem(R.id.action_menu).getActionView();
    Button b = (Button) v.findViewById(R.id.btnMenu);
    return super.onCreateOptionsMenu(menu);
}

由于某种原因,操作栏添加了不必要的项目,有人知道这种情况是如何发生的吗?

4

2 回答 2

0

您正在使用操作栏 sherlock。所以使用 SupportMenuInflater。

  public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
  com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
  inflater.inflate(R.layout.menu, menu);
  }

  public boolean onOptionsItemSelected(MenuItem item) {
  // Handle item selection
  switch (item.getItemId()) {
  case R.id.action_menu:
     // Intent i=new Intent(A.this,B.class);
      //startActivity(i);
      return true;
  }
  return false;

}

于 2013-05-23T09:54:37.940 回答
0

我发现了错误:我从所有项目中删除了 android:orderInCategory ,现在可以了,在这种情况下我不需要这个选项。

于 2013-05-23T10:54:59.120 回答