setsupportactionbar()引发错误 [英] setsupportactionbar() throws error

查看:259
本文介绍了setsupportactionbar()引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按照以下步骤在操作栏上方但在状态栏下方显示抽屉.在这里找到步骤:

I tried following the steps for displaying a drawer above the action bar but below the status bar. The steps found here: display over the ActionBar/Toolbar and under the status bar?

但是在实现代码之后,抛出了以下错误:
error: cannot find symbol method setSupportActionBar(Toolbar)
我已经在Google上搜索了此确切错误,而不是一个结果.

But after implementing the code, the following error was thrown:
error: cannot find symbol method setSupportActionBar(Toolbar)
I've searched on Google for this exact error and not a single result.

我正在使用Android Studio(1.1),并尝试使用清理构建"
我正在使用import android.support.v7.widget.Toolbar;

I'm using Android Studio (1.1) and have tried using "Clean Build"
I'm using import android.support.v7.widget.Toolbar;

Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
setSupportActionBar(toolbar); //error

希望有人能识别此错误并对此有一个快速的答案-否则,如果需要,我可以提供更多信息.

Hopefully, someone recognizes this error and has a quick answer for it - otherwise I can provide more information if requested.

推荐答案

编辑:

最近不推荐使用ActionBarActivity,而推荐使用ActionBarCompat.您应该使用新主题,并将其用作ActionBarCompat主题,例如Theme.AppCompat.Light

Recently ActionBarActivity has been deprecated in favor of ActionBarCompat. You should use the new one, and use as the ActionBarCompat themes, E.g. Theme.AppCompat.Light

您的类必须扩展ActionBarActivity而不是Activity才能使用方法setSupportActionBar

you class has to extend ActionBarActivity instead of Activity, in order to use the method setSupportActionBar

这篇关于setsupportactionbar()引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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