二进制 XML 文件第 10 行:在 API 级别 19 上膨胀 com.google.android.material.button.MaterialButton 类时出错。

4

实现'com.google.android.material:material:1.0.0'

但是当我在设备上运行api19时,头部出现错误。

针对此问题:

<style name = "Theme.MyApp" parent = "Theme.MaterialComponents.Light">
<style name = "Theme.MyApp" parent = "Theme.MaterialComponents.Light.Bridge">

我尝试了这些方法,但是没有得到结果。我该如何解决这个问题?

在其他安卓版本中,没有这个问题。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/google_login_button"
        app:icon="@drawable/google"
        app:layout_constraintStart_toStartOf="@+id/guideline"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintEnd_toStartOf="@+id/facebook_login_button"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintTop_toTopOf="@+id/facebook_login_button"
        app:layout_constraintBottom_toBottomOf="@+id/facebook_login_button"
        android:text="@string/google_button_text" app:cornerRadius="@dimen/login_screen_button_radius"/>

<com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/facebook_login_button"
        app:icon="@drawable/facebook"
        app:layout_constraintStart_toEndOf="@+id/google_login_button"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintEnd_toStartOf="@+id/twitter_login_button"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        android:text="@string/facebook_button_text" android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" app:cornerRadius="@dimen/login_screen_button_radius"/>

<com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/twitter_login_button"
        app:icon="@drawable/twitter"
        app:layout_constraintEnd_toStartOf="@+id/guideline2"
        app:layout_constraintStart_toEndOf="@+id/facebook_login_button"
        app:layout_constraintHorizontal_bias="0.5"
        android:layout_marginEnd="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/facebook_login_button"
        app:layout_constraintTop_toTopOf="@+id/facebook_login_button"
        android:text="@string/twitter_button_text" app:cornerRadius="@dimen/login_screen_button_radius"/>


那个错误不只是这样简单。 - TheWanderer
所有这些可绘制对象是在drawable文件夹中,还是在像drawable-v21这样的文件夹中? - forpas
在文件夹中的drawable。活动2个事情有activity_main.xml和activity_main.xml(21)。 - Yavuz
我有相同的错误。 - Yavuz
@Yavuz,请发布错误日志。 - forpas
显示剩余6条评论
1个回答

10

我知道现在有点晚了,但是对于未来会遇到这个问题的人们。将你的AppTheme的父级改为Theme.MaterialComponents。

之前的:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

之后

<!-- Material application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

它没有回答 OP 的问题。他明显有 Theme.MaterialComponents.Light.Bridge,你的答案并不是他提到的问题的解决方案。 - androidXP

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接