【问题标题】:How to put menu in actionbar with actionbarsherlock and slidemenu?如何将菜单放在actionbar中,带有actionBarsherlock和Slidemenu?
【发布时间】:2014-09-17 06:38:33
【问题描述】:

所以我一直在尝试使用 actionbarsherlock 和 slidemenu 在操作栏中获取菜单。

但菜单显示在底部而不是操作栏中。我做错了什么?

这是一个截图:http://imgur.com/aB4sUWD screenshot

我已经覆盖了 onOptionsItemSelected 和 onCreateOptionsMenu 方法。但它的菜单只是没有显示在顶部。 :(

public class MainActivity extends SlidingFragmentActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    arcList = new MenuFragment(this);

    for (Registry item : Registry.values())
        arcList.addItem(item.name(), item.iconR);

    // set the Above View
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_frame, Registry.Build.getFragmentList())
            .commit();

    // configure the SlidingMenu
    menu = new SlidingMenu(this);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
    menu.setMenu(R.layout.menu_frame);

    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.menu_frame, arcList)
            .commit();

    arcList.lastItemList = Registry.Build;

    setSlidingActionBarEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    View customNav = LayoutInflater.from(this).inflate(R.layout.navigation, null);
    getSupportActionBar().setCustomView(customNav);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);

    menu.showMenu();
    setTitle("Build");
    getSupportActionBar().setIcon(Registry.Build.iconR_i);

    setContentView(R.layout.content_frame);
    setBehindContentView(R.layout.content_frame);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            toggle();
            return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    getSupportMenuInflater().inflate(R.menu.menu, menu);
    return true;
}

}

这里是 menu.xml:

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu" android:icon="@drawable/randomicon"
      android:title="@string/menutitle!" android:titleCondensed="@string/randomtitle" android:visible="true"/>
    </menu>

非常感谢任何帮助或提示。

【问题讨论】:

    标签: android actionbarsherlock


    【解决方案1】:

    有趣的是,在尝试了 5 个小时之后,我放弃并在这里询问的那一刻我找到了解决方案 ~.~

    原来 android:uiOptions="splitActionBarWhenNarrow" 一直在 androidmanifest 中设置,而我没有注意到。

    【讨论】:

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