Android Studio 3.5+ 使用androidx的r

2019-10-21  本文已影响0人  明早天气不错

Android逐渐淘汰support之前的版本,Android studio 导入support.v7也会出错。

在Android developers中找到了添加依赖项的方法:

dependencies {

def recyclerview_version = "1.0.0"

implementation "androidx.recyclerview:recyclerview:$recyclerview_version"

// For control over item selection of both touch and mouse driven selection

implementation "androidx.recyclerview:recyclerview-selection:$recyclerview_version"

}

在build.gradle(Module:app)中找到dependencies,在括号里面输入上述文字。修改布局文件如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView

        android:id="@+id/recycler_view"

        android:layout_width="match_parent"

        android:layout_height="match_parent"/>

</LinearLayout>

然后就可以使用了

上一篇 下一篇

猜你喜欢

热点阅读