【问题标题】:android - Action bar sherlock add unnecessary buttonandroid - 动作栏夏洛克添加不必要的按钮
【发布时间】:2013-05-23 18:54:59
【问题描述】:

我使用操作栏 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);
}

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

【问题讨论】:

  • “不必要的物品”是什么意思?
  • 我认为他在抱怨溢出按钮
  • 你能发一张截图来帮助我们弄清楚你说的是什么按钮吗?

标签: android actionbarsherlock


【解决方案1】:

您正在使用操作栏 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;

}

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多