android.widget.Toolbar不能转换为android.support.v7.widget.Toolbar [英] android.widget.Toolbar cannot be converted to android.support.v7.widget.Toolbar

查看:4392
本文介绍了android.widget.Toolbar不能转换为android.support.v7.widget.Toolbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个toolbar.xml:

I have a toolbar.xml:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark" />

我有一个包括标签到另一个我的活动布局:

I have an include tag to another of my activity layouts:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme">

<include
    layout="@layout/toolbar"
    android:id="@+id/tb">
</include>

<android.support.v7.widget.RecyclerView
    android:id="@+id/grade_list"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF" />


我有它在我的活动延伸AppCompatActivity实现的:

And I have it implemented in my activity which extends AppCompatActivity:

Toolbar toolbar;
    toolbar = (Toolbar)findViewById(R.id.tb);
    setSupportActionBar(toolbar);

不过,我收到以下错误,当我跑我的应用程序:

However, I am getting the following error when I run my app:

Error:(26, 29) error: incompatible types: android.widget.Toolbar cannot be converted to android.support.v7.widget.Toolbar

此外,当我在编辑器中查看我的布局,我收到以下消息:

Furthermore, when I view my layout in the editor, I receive the following message:

Missing styles. Is the correct theme chosen for this layout?
Use the theme combo box above the layout to choose a different layout, or to fix the theme style references.
Failed to find style 'toolbarStyle' in current layout.

和我styles.xml:

And my styles.xml:

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/color_primary</item>
    <item name="colorPrimaryDark">@color/color_primaryDark</item>
    <item name="colorAccent">@color/color_accent</item>
    <item name="colorControlNormal">@color/color_accent</item>
</style>

我不明白我要去的地方错了。正确的主题编辑器,我的清单文件中选择。所有帮助pciated一如既往AP $ P $!

I don't see where I am going wrong. The correct theme is selected in the editor and my manifest file. All help is appreciated as always!

推荐答案

您使用 android.support.v7.widget.Toolbar 在你的XML,但在你的java code您导入 android.widget.Toolbar 这是一个不同的类型。导入更改为 android.support.v7.widget.Toolbar ,它应该工作。

You use android.support.v7.widget.Toolbar in your XML, but in your java code you are importing android.widget.Toolbar which is a different type. Change your import to android.support.v7.widget.Toolbar and it should work.

这篇关于android.widget.Toolbar不能转换为android.support.v7.widget.Toolbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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