以下代码与轮廓输入框完美配合。
<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>
我在整个应用程序中设置了自定义字体。通过以下代码设置后,它崩溃了。以下样式用于应用程序主题。
<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.
包名称的一部分),要求您使用 Material 主题。
此页面列出了要使用的适当主题:
https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#4-change-your-app-theme-to-inherit-from-a-material-组件主题 https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#4-change-your-app-theme-to-inherit-from-a-material-components-theme
您必须从此更改应用程序的主题
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
例如这
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)