渲染期间引发异常:查看未使用正确的上下文创建的android.support.v7.widget.Toolbar

Jua*_*via 5 android android-layout android-support-library android-studio

我在Android预览设计器中收到此错误消息为"渲染问题".我正在使用API​​ 22来渲染和迁移到新的API支持v4:22.1+和v7:22.1+.

Rendering Problems Exception raised during rendering: View android.support.v7.widget.Toolbar not created with the right context

渲染问题

场景:

  • 使用Android Studio v1.2RC
  • 渲染API v22(更改为21或19无法解决)
  • 将ActivityBarActivity迁移到AppCompatActivity
  • 编译部分:

    compile 'com.android.support:support-v4:22.1.+' compile 'com.android.support:appcompat-v7:22.1.+'

  • 工具栏

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" android:background="?attr/colorPrimary" android:elevation="4dp" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/Theme.AppCompat" />

Jua*_*via 3

导致该错误的原因是我必须在工具栏布局中删除“app”部分,并将“app:”更改为“android:”。

消除:

xmlns:app="http://schemas.android.com/apk/res-auto"

代替:

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/Theme.AppCompat"

为了:

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:popupTheme="@style/Theme.AppCompat"