二进制 XML 文件第 10 行:为 API 级别 19 增加类 com.google.android.material.button.MaterialButton 时出错

Yav*_*vuz 4 java migration android androidx

实现 '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">
Run Code Online (Sandbox Code Playgroud)

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

在其他android版本中,没有问题。

<?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"/>
Run Code Online (Sandbox Code Playgroud)

小智 9

我知道这有点晚了,但对于那些将来会遇到这个问题的人来说。将您的 AppTheme 父项更改为 Theme.MaterialComponents

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>
Run Code Online (Sandbox Code Playgroud)

<!-- Material application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>
Run Code Online (Sandbox Code Playgroud)