【问题标题】:Android XML Preview - "The following classes could not be found"Android XML 预览 - “找不到以下类”
【发布时间】:2015-08-17 12:42:16
【问题描述】:

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

找不到以下类: - com.gc.materialdesign.views.Button(修复构建路径,创建类) 提示:尝试构建项目。

我已经进行了构建、清理、重启 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 预览窗口上预览按钮。

谢谢大家!

【问题讨论】:

  • 大部分情况下我认为您使用的是 gradle 1.2.2 尝试使用 gradle 1.2.3 或降级到 1.2.1。
  • @siris_cac 实际上我有 gradle 版本 1.2.3,试图降级到 1.2.1 但没有任何改变。还有其他解决方案吗?
  • 请分享您添加按钮的布局代码。
  • 我使用简单的布局,最简单的情况。检查我编辑的问题@AnandSingh

标签: android xml android-studio gradle preview


【解决方案1】:

请尝试以下代码:

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

在您使用的代码中

编译'com.github.navasmdc:MaterialDesign:1.5@aar'

库,但您没有使用它的代码样式。请参考https://github.com/navasmdc/MaterialDesignLibrary 了解更多信息。

我希望这对你有用。

【讨论】:

【解决方案2】:

转到应用程序>右键单击它>打开模块设置>将构建工具版本更改为22.0.1 希望对你有用

【讨论】:

  • 感谢您的评论。但它并没有解决我的问题。
【解决方案3】:

如果有人遇到同样的问题,这就是我设法解决问题的方法:

将 Android Studio 1.2.1.1 降级到 1.1.0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-25
    • 1970-01-01
    相关资源
    最近更新 更多