我正在尝试使用 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/