我正在尝试使用 ActionBarSherlock 实现底部菜单。在 Android 2.1 中显示菜单,但在 Android 4 中不显示菜单。怎么了?
下面,代码:
public class Atividade extends Activity implements OnCreateOptionsMenuListener {
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT < 11)
// Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
mSherlock.setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
mSherlock.setContentView(R.layout.atividade);
.
.
.
}
下面是菜单选项:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Agenda")
.setIcon(R.drawable.ic_compose)
// .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add("Favoritos")
.setIcon(R.drawable.favoritos)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add("Mapa")
.setIcon(R.drawable.maps)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
com.actionbarsherlock.view.SubMenu subMenu1 = menu.addSubMenu("Compartilhar");
subMenu1.add("Facebook");
subMenu1.add("Twitter");
subMenu1.add("E-Mail");
subMenu1.add("SMS");
MenuItem subMenu1Item = (MenuItem) subMenu1.getItem();
subMenu1Item.setIcon(R.drawable.compartilhar);
subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
}