android - 如何解决 Android 错误 "method setSupportActionBar in class AppCompatActivity cannot be applied to given types"?

标签 android android-support-library android-appcompat android-toolbar android-actionbar-compat

我正在使用 com.android.support:appcompat-v7:23.0.3 使用 appcompat 制作 Android 应用程序并出现以下错误。

Error:(22, 9) error: method setSupportActionBar in class AppCompatActivity cannot be applied to given types; required: android.support.v7.widget.Toolbar found: android.widget.Toolbar reason: actual argument android.widget.Toolbar cannot be converted to android.support.v7.widget.Toolbar by method invocation conversion

最佳答案

首先,appcompat 23.0.3 不存在

使用23.0.1

com.android.support:appcompat-v7:23.0.1

然后 method setSupportActionBarandroid.support.v7.widget.Toolbar 配合使用。

检查代码中的导入
当您使用工具栏时,您必须使用正确的导入:

import android.support.v7.widget.Toolbar;

最后,在您的布局中,您必须使用正确的小部件。

<android.support.v7.widget.Toolbar
    ..... />

关于android - 如何解决 Android 错误 "method setSupportActionBar in class AppCompatActivity cannot be applied to given types"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32678542/

相关文章:

android - 两个 RecyclerView 依赖项有什么区别?

android - 如何阻止我的 AutoCompleteTextView 下拉菜单在我的 AutoCompleteTextView 上滚动?

android - 错误:无法获得类型为org.gradle.api.Project的项目 'appcompat'的未知属性 ':app'

Android - AsyncTask 没有返回到主 Activity 的结果

java - URLEncoder 中的 NullPointerException

java - Eclipse - 项目包含错误但未发现

Android appcompat 主题始终显示黑色操作栏

java - 如何更改默认自定义对话框的边框颜色?

Android 使用支持库来支持 SearchView

android - ActionBarActivity 在按下硬件菜单按钮后关闭。没有堆栈跟踪