使用 AndroidX 概述的 TextField

Outlined TextField with AndroidX

我将项目更新为 androidx:

implementation 'androidx.appcompat:appcompat:1.0.0'

现在 中带有 MaterialComponents 的 OutlinedBox 导致我的应用程序崩溃。

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

我可以用 editText 背景创建轮廓作为背景 (),但是有没有办法用 androidx 和 material 组件做到这一点?或许我还遗漏了什么?

样式style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"属于Material个组件,您需要通过添加这个依赖来实现它:implementation 'com.google.android.material:material:1.1.0-alpha06'。并记得从 Material 组件继承您的应用主题:

<style name="MyAppTheme" parent="Theme.MaterialComponents.Light.Bridge">
    <!-- ... -->
</style>

更多详情,您可以阅读this guide