J'écrirai ce qu'il faut faire après avoir introduit la conception matérielle dans le projet Android. Ceci est fait pour Hello world après avoir créé un projet Android.
Pour introduire la conception matérielle, écrivez build.gradle comme suit.
 build.gradle
    // material design
    api 'com.google.android.material:material:1.2.0-alpha06'
Écrivez res / values / styles.xml comme suit.
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
Changez res / layout / activity_main.xml et vérifiez l'affichage.
<?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">
    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Vérification"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        />
</androidx.constraintlayout.widget.ConstraintLayout>
Confirmez que l'affichage suivant est affiché

Si vous laissez res / values / styles.xml dans l'état par défaut, l'erreur suivante s'affichera.
Error inflating class com.google.android.material.button.MaterialButton
Recommended Posts