如何在AndroidX中的布局xml中添加cardview [英] How to add cardview in layout xml in AndroidX

查看:1538
本文介绍了如何在AndroidX中的布局xml中添加cardview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在AndroidX中的布局xml中添加cardview

How to add cardview in layout xml in AndroidX

升级到AndroidX后

After upgraded to AndroidX

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

出现错误

找不到以下类: -android.support.v7.widget.CardView(修复构建路径,编辑XML,创建类)

The following classes could not be found: - android.support.v7.widget.CardView (Fix Build Path, Edit XML, Create Class)

dependencies {

    implementation 'androidx.appcompat:appcompat:1.0.0'

    implementation 'androidx.cardview:cardview:1.0.0'

但是我不知道如何在AndroidX下的xml中使用CardView

but I don't know how to use CardView in xml under AndroidX

谢谢

推荐答案

该类已更改为:

androidx.cardview.widget.CardView

如果要使用旧的类名,则需要在gradle.properties中添加android:enableJetifier=true并改用appcompat依赖项.

If you want to use the old class names, you need to add android:enableJetifier=true to your gradle.properties and use the appcompat dependencies instead.

这篇关于如何在AndroidX中的布局xml中添加cardview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆