添加 material 依赖项后显示 TextInputLayout 错误

Showing errors with TextInputLayout after adding material dependency

我只想知道为什么我的所有 TextInputLayout 在添加 material 依赖项后都没有应用轮廓样式。实际上,我在我的项目中实现了徽章可绘制对象和 tabmediator 的 material 依赖项,因此如果删除该依赖项,我的 tablayout 将会崩溃。那么,我该怎么办,求解决方案

build.gradle


        dependencies {
            implementation fileTree(dir: "libs", include: ["*.jar"])
            implementation 'androidx.appcompat:appcompat:1.2.0'
            implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
            implementation 'com.android.support:design:29.0.0'
            implementation 'com.android.support:appcompat-v7:29.1.0'
        
            implementation 'com.google.android.material:material:1.3.0-alpha02'
            implementation 'androidx.legacy:legacy-support-v4:1.0.0'
            implementation 'androidx.palette:palette:1.0.0'
            implementation "androidx.viewpager2:viewpager2:1.1.0-alpha01"
        
        
            testImplementation 'junit:junit:4.12'
            androidTestImplementation 'androidx.test.ext:junit:1.1.1'
            androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    
    }

style.xml


    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
    <!--        <item name="android:statusBarColor">#00000000</item>-->
        </style>
    
        <style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
    
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowActionBar">false</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowContentOverlay">@null</item>
        </style>
    
    </resources>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jmm.rkclasses">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:exported="true"
            android:theme="@style/FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:theme="@style/FullScreen">
]
        </activity> 
    </application>

</manifest>

LoginActivity.xml

<?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"
    android:background="@drawable/bg_login"
    tools:context=".LoginActivity">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="32dp"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintGuide_end="24dp"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="30dp"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintGuide_end="30dp" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:fontFamily="@font/oxygen"
        android:text="Welcome,"
        android:textColor="@color/colorPrimary"
        android:textSize="24sp"
        app:layout_constraintBottom_toTopOf="@+id/guideline2"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toTopOf="@+id/guideline"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/oxygen"
        android:text="Log In"
        android:textColor="@color/colorPrimary"
        android:textSize="36sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="@+id/textView"
        app:layout_constraintStart_toStartOf="@+id/textView"
        app:layout_constraintTop_toBottomOf="@+id/textView" />


    <Spinner
        android:id="@+id/spn_user_type"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_marginTop="32dp"
        android:background="@drawable/closed_edit_text"
        app:layout_constraintEnd_toStartOf="@+id/guideline4"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/textView2"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout2"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="0dp"
        android:layout_height="55dp"
        android:layout_marginTop="8dp"
        android:hint="Username"
        android:paddingVertical="0dp"
        app:boxStrokeColor="@color/colorPrimary"
        app:layout_constraintEnd_toEndOf="@+id/spn_user_type"
        app:layout_constraintStart_toStartOf="@+id/spn_user_type"
        app:layout_constraintTop_toBottomOf="@+id/spn_user_type">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/et_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="0dp"
        android:layout_height="55dp"
        android:layout_marginTop="8dp"
        android:hint="Password"
        app:layout_constraintEnd_toEndOf="@+id/textInputLayout2"
        app:layout_constraintStart_toStartOf="@+id/textInputLayout2"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout2"
        app:passwordToggleContentDescription="description"
        app:passwordToggleDrawable="@drawable/show_password_selector"
        app:passwordToggleEnabled="true"
        app:passwordToggleTint="@color/colorPrimary">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        android:id="@+id/tv_fgt_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Forget Password?"
        android:textColor="@color/colorPrimaryDark"
        app:layout_constraintEnd_toEndOf="@+id/textInputLayout"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />

    <Button
        android:id="@+id/btn_login"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_marginStart="40dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="40dp"
        android:background="@drawable/bg_blue_red_button"
        android:fontFamily="@font/oxygen"
        android:text="Log In"
        android:textAllCaps="false"
        android:textColor="@color/colorWhite"
        android:textSize="22sp"

        app:layout_constraintBottom_toTopOf="@+id/guideline2"
        app:layout_constraintEnd_toStartOf="@+id/guideline4"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toBottomOf="@+id/tv_fgt_password"
        app:layout_constraintVertical_bias="0.22000003" />


</androidx.constraintlayout.widget.ConstraintLayout>

更改前 Before changes

修改后 After changes

您必须使用 MaterialComponents 主题而不是 AppCompact 主题。

为此,将您的 style.xml 文件替换为:

    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
    <!--        <item name="android:statusBarColor">#00000000</item>-->
        </style>
    
        <style name="FullScreen" parent="Theme.MaterialComponents.Light.NoActionBar">
    
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowActionBar">false</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowContentOverlay">@null</item>
        </style>
    
    </resources>

您必须切换到 Material Components Theme:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
  <!-- ....  -->
</style>

请注意。
删除这些依赖项,因为它们不存在。

  //implementation 'com.android.support:design:29.0.0'
  //implementation 'com.android.support:appcompat-v7:29.1.0'