渲染期间引发异常:视图 android.support.v7.widget.Toolbar 未使用正确的上下文创建
Exception raised during rendering: View android.support.v7.widget.Toolbar not created with the right context
我在 Android 预览设计器中收到此错误消息 "Rendering Problems"。我正在使用 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
- 渲染APIv22(改成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"
/>
错误是因为我必须在工具栏布局中删除 "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"
I solved this problem by Downgrading API level from 22,21 to 20 as shows
in below image
我在 Android 预览设计器中收到此错误消息 "Rendering Problems"。我正在使用 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
- 渲染APIv22(改成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" />
错误是因为我必须在工具栏布局中删除 "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"
I solved this problem by Downgrading API level from 22,21 to 20 as shows in below image