带有操作栏 Sherlock 的菜单 [英] Menu with action bar sherlock

查看:20
本文介绍了带有操作栏 Sherlock 的菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个例子或教程关于如何使用操作栏 Sherlock 添加菜单项

I need an example or a tutorial on how to add menu items with action bar sherlock

当我使用简单菜单时与进口

When I use the simple menu with the imports

import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

当我打电话时

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

    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.goToSettings:
            startActivity(new Intent(this, SetPreference.class));
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }

    }

然后我从 SherlockActivity 错误中得到无法覆盖最终方法.

then I get the Cannot override the final method from SherlockActivity error.

推荐答案

您必须使用 MenuMenuInflaterMenuItem 类来自 <代码>com.actionbarsherlock.view 包:

You have to use Menu, MenuInflater and MenuItem classes from com.actionbarsherlock.view package:

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.settings_menu, menu);

    return super.onCreateOptionsMenu(menu);
}

顺便说一句,ActionBarSherlock 包含很多示例.

BTW, ActionBarSherlock contains a lot of samples.

这篇关于带有操作栏 Sherlock 的菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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