5

我在Android預覽設計器中收到此錯誤消息爲「呈現問題」。我正在使用API​​ 22來渲染並遷移到新的API支持v4:22.1+和v7:22.1+。在呈現過程中出現異常:查看android.support.v7.widget.Toolbar未使用正確的上下文創建

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

Rendering Problems

場景:

  • 使用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" />

+0

你真的需要依靠IDE顯示 ?學習XML,您仍然可以自己構建UI。 –

+2

完全使用您的IDE沒有任何問題。 OP從未說過他們用IDE在視覺上構建了UI。大多數情況下,他們只是試圖使用預覽功能,而這恰好是在UI中充實XML的最快方式。 – gMale

回答

3

錯誤是造成的,因爲我在工具欄佈局刪除的 「應用」 部分和變化「 app:'by'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"

+1

謝謝我已經看到這個問題數週了,並厭倦了切換預覽的主題來解決它。這工作,完美。 – gMale

3

我解決了這個問題,通過從降級API 22,21級20如下圖像

enter image description here

相關問題