因此,我一直在尝试在操作栏中使用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>任何帮助或提示都是非常感谢的。
发布于 2014-07-25 20:42:22
有趣的是,在尝试了5个小时后,当我放弃并在这里提问的时候,我找到了解决方案~~
原来android:uiOptions="splitActionBarWhenNarrow“一直都是在along清单中设置的,我没有注意到。
https://stackoverflow.com/questions/24955197
复制相似问题