<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints"
android:background="@color/material_dynamic_primary40">
报错,app无法启动 Error inflating class androidx.appcompat.widget.LinearLayoutCompat
错误原因:android:background="@color/material_dynamic_primary40">
修改方法:
在color.xml中添加
<color name="blue">#0099FF</color>
再把background改成
android:background="@color/blue"
其他试过的方法(无用):
修改build.gradle,添加
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
参考: