我在使用来自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