Rendering exception: Viewing android.support.v7.widget.Toolbar not created with the correct context

I get this error message in Android Preview Designer as "Rendering Issues". I am using API 22 to render and port to the new support for API v4: 22.1+ and v7: 22.1 +.

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

Rendering Problems

Scenario:

  • Using Android Studio v1.2RC
  • Render API v22 (changing to 21 or 19 does not allow it)
  • Migrating ActivityBarActivity to AppCompatActivity
  • Compilation Section:

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

  • Toolbar

    <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" />

+5
source share
2 answers

The error was caused by the fact that I had to delete the "application" section in the toolbar layout and change "application:" to "android:".

Delete

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

Replace:

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

For:

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

+3
source

I solved this problem by lowering the API level from 22.21 to 20, showing below images

enter image description here

+3
source

All Articles