获取选项菜单,在系统栏中显示 [英] Get options menu to show in system bar

查看:121
本文介绍了获取选项菜单,在系统栏中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的选项菜单在新的Andr​​oid 3.0系统栏显示出来。我能得到这个行为与Notepadv3教程。然而,几乎实现相同功能时,菜单显示在上面的操作栏,但不系统吧。任何想法?

I'm trying to get my options menu to show up in the new Android 3.0 system bar. I can get this behavior to work with the Notepadv3 tutorial. However, when implementing nearly the identical functions, the menu shows in the above action bar, but not the system bar. Any ideas?

附件为我的应用选择合适的code:

Attached is the appropriate code for my application:

public class AACUser extends Activity {


private static final int ADMIN_ID = Menu.FIRST;

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, ADMIN_ID, 0, R.string.menu_admin);
    return true;
}


@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch(item.getItemId()) {
        case ADMIN_ID:
            enterAdminMode();
            return true;
        default:
            return super.onMenuItemSelected(featureId, item);
    }
}


}

我也尝试实现这些菜单功能由创建菜单文件recomended

public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.user_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.menu_adminMode:
            enterAdminMode();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

但没有任何区别:它仍然显示在操作栏中的溢出选项,但不是系统栏

but no difference: it still displays the option in the overflow of the action bar, but not the system bar.

推荐答案

随着Android 3.0的时,选项菜单不是必需的(即使不是在precated)。如果你的目标API 11(Android 3.0的)或更高版本,假设您的应用程序将不使用选项菜单中工作,因此系统栏将不会显示的。在系统栏中的选项菜单仅是为了与旧应用程序的向后兼容性。新的应用程序应该有另一个启示访问选项,如通过操作栏提供的。

As of Android 3.0, the options menu is not required (if not deprecated). If you target API 11 (Android 3.0) or later, it is assumed that your app will work without an options menu, so the system bar will not display one. The options menu in the system bar is only there for backwards compatibility with old applications. New applications should have another affordance for accessing options, such as that provided by the action bar.

这篇关于获取选项菜单,在系统栏中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆