android - 为 App 设置自定义主题时 TextInputLayout 崩溃
问题描述
以下代码与大纲输入框完美配合。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/notes"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/text_notes"
app:boxBackgroundColor="@color/colorWhite">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_notes"
android:fontFamily="sans-serif-black"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
我在整个应用程序中设置了自定义字体。通过以下代码设置后,它正在崩溃。以下样式用于 App 主题。
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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:textViewStyle">@style/SansSerifTextViewStyle</item>// Custom font style
<item name="buttonStyle">@style/SanSerifButtonStyle</item> // Custom font style
</style>
当我删除以下行时,应用程序不会崩溃。但概述的框 UI 不会出现。尝试通过Java代码设置,不工作。
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
解决方案
材料组件,如com.google.android.material.textfield.TextInputLayout
(注意.material.
包名称的一部分),要求您使用材料主题。
此页面列出了要使用的适当主题:
您必须从此更改应用程序的主题
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
例如这个
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
推荐阅读
- javascript - 如果服务器上不存在图像 url,则将 url 替换为其他(多次)
- python - 获取用于 seaborn 绘图的 bin 宽度
- c# - 在 C# 中使用 gRPC 子通道进行负载平衡
- c# - 按键冷却时间
- javascript - Edge & IE: Permission Denied after creating an iframe and accessing window object
- java - 如何修复 Android Studio 中的崩溃
- c++ - 设计模式中对象的过程(方法和操作)状态
- java - Java 中与 C# 兼容的 XML 转换
- angular - Ionic 4 Angular 中缺少“mobileweb”平台
- python - AttributeError: module 'requests' has no attribute 'post'. is it deprecated and new function has been introduced?