android - Android XML预览- “The following classes could not be found”

标签 android xml android-studio gradle preview

我正在尝试使用 Material 库:Material;但是当我添加一个按钮(从库)时,Android Studio(1.2.1.1)的Xml预览不断向我返回错误:

The following classes could not be found: - com.gc.materialdesign.views.Button (Fix Build Path, Create Class) Tip: Try to build the project.



我已经完成了构建,清理,重新启动Android Studio,在XML编辑器上更改预览API的操作,但似乎没有任何效果。

在build.grade上,我对此进行了修改以添加库:
repositories {
    jcenter()
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:22.0.0'
  compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
}

其他资讯:
minSDK = 16
targetSDK=21
compileSDK=21
gradle Version = 1.2.3

test_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f">

<com.gc.materialdesign.views.Button
    android:id="@+id/login_btn_login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="button text"/>
</RelativeLayout>

XML预览消失后,我还能为该错误做什么?该应用程序运行没有任何错误,但是我无法在XML预览窗口上预览按钮。

谢谢你们!

最佳答案

请尝试以下代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f">

<com.gc.materialdesign.views.ButtonFlat
            android:id="@+id/buttonflat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#1E88E5"
            android:text="Button" />
</RelativeLayout>

在您的代码中,您正在使用

compile 'com.github.navasmdc:MaterialDesign:1.5@aar'



库,但您没有使用其代码样式。有关更多信息,请引用https://github.com/navasmdc/MaterialDesignLibrary

希望这对您有用。

关于android - Android XML预览- “The following classes could not be found”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30617829/

相关文章:

javascript - 从字符串创建 SVG 对象

html - 在存储过程中使用 XML 在 <td> 中设置不同的 bgcolor

android - 如何自动将 ListView 字段的第一行传递给 EditText 字段

android-studio - 虚拟设备目标 (Android null) - Android Studio

android - 如何构建或从哪里获得支持 Fortran 的 Android NDK 独立工具链?

java - 如何在ehcache.xml中配置QueryCache

java - 为什么这个错误: Could not find class 'oauth.路标.http.HttpParameters

java - 如何从接收到的数据中正确提取信息?

android - 是否可以将 ViewGroups 项目带到 ViewGroups sibling 的前面?

android - Koin + Retrofit 在运行时添加标题