如何使用 androidx 库而不是 android.support.v7.widget.CardView

how to use androidx library instead of android.support.v7.widget.CardView

我想重新设计我的应用程序,我已经在这附近检查了一些代码,但我没有发现它已更新为 compileSdkVersion 30 并使用 androidX 进行布局,而不是 android.support.v7。我的 SDK 是 30。下面是我在这个网站上找到的代码。

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<View
    android:id="@+id/view_blank"
    android:layout_width="match_parent"
    android:layout_height="260dp"
    android:background="@color/colorPrimary"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"/>

<ImageView
    android:id="@+id/image_logo"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:layout_marginTop="80dp"
    android:src="@drawable/ic_action_facebook"
    android:tint="@android:color/white"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"/>


<android.support.constraint.ConstraintLayout
    android:id="@+id/credentials_card"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="20dp"
    android:padding="@dimen/spacing_mlarge"
    app:layout_constraintTop_toBottomOf="@+id/image_logo"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/spacing_medium"
        android:visibility="visible"
        app:cardUseCompatPadding="true"
        app:cardCornerRadius="6dp"
        app:cardElevation="5dp"
        tools:ignore="MissingConstraints">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/spacing_xmlarge">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="25dp"
                android:text="SIGN IN"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/colorAccent"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="USERNAME"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/colorPrimary" />

            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/colorPrimary"
                android:textStyle="bold"
                android:theme="@style/EditText.Grey" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="PASSWORD"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/colorPrimary" />

            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/colorPrimary"
                android:textStyle="bold"
                android:theme="@style/EditText.Grey" />


        </LinearLayout>

    </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

<Button
    android:id="@+id/sign_up"
    android:layout_width="match_parent"
    android:layout_height="57dp"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:background="@drawable/btn_rounded_primary"
    android:text="S I G N  I N"
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="@+id/credentials_card"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"/>


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:layout_marginTop="20dp"
    android:text="FORGET PASSWORD"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
    android:textColor="@color/grey_40"
    android:textStyle="bold"
    app:layout_constraintTop_toBottomOf="@+id/sign_up"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"/>

我无法对 post 编写代码的人发表评论,因为我对它的水平不高,所以我正在尝试为其创建一个新线程。

OutPut enter image description here

这是 post 我从

找到的

您可以使用新的 cardview 依赖项 androidx.cardview:cardview:1.0.0

并且在 xml 中使用 <androidx.cardview.widget.CardView/> 而不是 <android.support.v7.widget.CardView/>