所以我一直试图通过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>
非常感谢任何帮助或提示。
答案 0 :(得分:1)
有趣的是,经过5个小时尝试的例子,我放弃的那一刻,在这里问我找到了解决方案〜。
原来android:uiOptions =“splitActionBarWhenNarrow”一直在androidmanifest中设置,没有我注意到。