我在使用來自Google支持庫(appcompat-v7,support-v4)的類時在Android Studio中呈現佈局預覽時出現問題。Android Studio - 呈現支持庫問題
範例(同樣適用於所有其他元素從支持庫):
以下類找不到: - android.support.v7.widget.Toolbar(修復構建路徑,編輯XML ,創建類)
的庫添加到的build.gradle的依賴列表:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
}
的事情是,當我將XML中的類名更改爲<Toolbar>
而不是<android.support.v7.widget.Toolbar>
時,所有內容都完美呈現,但不會在較早的API版本上運行。更改渲染API版本不會修復它,也不會更改應用程序主題或構建/清理項目。
該應用程序在新舊API上運行時沒有任何問題 - 這只是渲染讓我感到惱火,因爲我試過了Stack Overflow上關於這些問題的一切,而且我仍然無法修復它。在我看來,Android Studio佈局渲染器沒有看到依賴列表中添加的類。
下面是我的自定義應用程序工具欄的代碼:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="@dimen/padding_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
app:theme="@style/CustomToolbarTheme"
/>
我有同樣的問題,沒有我嘗試過的方法工作。類似的事情發生之前,並始終與Android Studio的下一個更新固定,所以我們希望.. – Lamorak
重新安裝Android Studio和Android SDK +開始一個新的新項目也沒有幫助。自從版本1.1或更高版本以來,我一直在對付這個問題..但是很高興知道我不是唯一一個:) – Recycling