【问题标题】:MaterialComponents >1.0.0 reverts back to AppCompatMaterialComponents >1.0.0 恢复为 AppCompat
【发布时间】:2020-03-04 07:18:19
【问题描述】:

我在我的应用程序中尝试了 MaterialComponents 1.0.0 来使用轮廓文本框设计。一切都很好,但我也想使用startIconDrawable 属性。事实证明,我必须至少更新到 1.1.0 才能这样做。我做到了,但自从更新后,整个设计恢复到 AppCompat 风格。

这里有一些代码

build.gradle(应用模块)

...
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'
    implementation 'com.google.android.material:material:1.2.0-alpha01'
}

编辑:也试过1.1.0-beta01

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/colorPrimary</item>
    </style>
</resources>

fragment.xml

...
<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/registerDate"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/date"nt"
        app:layout_constraintTop_toTopOf="parent"
        app:startIconDrawable="@drawable/outline_calendar_today_24">

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

预期

实际

【问题讨论】:

  • 尝试使用 1.1.0-beta01 版本而不是 1.2.0-alpha01 版本
  • 我也试过了。抱歉,我把它从帖子中遗漏了。
  • 这很奇怪。活动是否使用 AppTheme 主题?按钮也很奇怪。
  • 是的,它确实使用了 AppTheme。在使用 MaterialComponent 1.0.0 时,它看起来就像在第一个屏幕截图中一样。

标签: android material-components


【解决方案1】:

我决定从头开始重新创建项目,现在一切都很好。

我发布这个答案是因为我遇到了其他看似无关的问题,并且有几个答案说在 Android Studio 中清理缓存可以解决这些问题。

我没有尝试通过清理缓存来解决这个问题,但它可能可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2019-10-09
    • 2019-10-22
    • 2021-03-28
    • 2020-09-01
    • 1970-01-01
    相关资源
    最近更新 更多