как использовать Android Материал Дизайн в android - PullRequest
0 голосов
/ 02 апреля 2020

Я пытаюсь использовать Компоненты дизайна материала в Android проекте, я следовал этому учебнику (на веб-сайте Material Design), я также изменил тему, использованную в макете моей деятельности, и я также расширяю мою активность до AppCompatActivity, но у меня есть эта ошибка:

2020-04-02 19:22:11.103 11696-11696/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ecoleenligne, PID: 11696
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ecoleenligne/com.example.ecoleenligne.LoginActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    ...
 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:555)
    at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.example.ecoleenligne.LoginActivity.onCreate(LoginActivity.java:12)
    ...

МОЙ макет активности:

  <?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=".LoginActivity">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Blabla"
        app:layout_constraintBottom_toBottomOf="parent"
        >

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="340dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

Мой Gradle:

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.example.ecoleenligne"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'


}

Мой стиль. xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="ThemeOverlay.MaterialComponents">
        <!-- Customize your theme here. -->

    </style>

</resources>
...