首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Widget.Material3 TextAppearance属性错误

Widget.Material3 TextAppearance属性错误
EN

Stack Overflow用户
提问于 2022-02-08 17:01:24
回答 1查看 225关注 0票数 2

虽然从材料样式中使用这种样式,但我在AppTheme中提供的AppTheme或扩展该样式本身并提供TextAppearance的位置并不重要

该应用程序崩溃时有以下错误:

E/AndroidRuntime:由:java.lang.IllegalArgumentException引起的:这个组件需要指定一个有效的TextAppearance属性。更新您的应用程序主题,以继承从Theme.MaterialComponents (或后代)。在com.google.android.material.internal.ThemeEnforcement.checkTextAppearance(ThemeEnforcement.java:185) at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:116) at com.google.android.material.textfield.TextInputLayout.(TextInputLayout.java:474) at com.google.android.material.textfield.TextInputLayout.(TextInputLayout.java:433)

XML组件如下所示

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/txtcountry"
    style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/_10sdp"
    android:hint="@string/select_country"
    android:textColorHint="@color/dark_blue"
    app:boxCornerRadiusBottomEnd="@dimen/_10sdp"
    app:boxCornerRadiusBottomStart="@dimen/_10sdp"
    app:boxCornerRadiusTopEnd="@dimen/_10sdp"
    app:boxCornerRadiusTopStart="@dimen/_10sdp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:startIconDrawable="@drawable/ic_baseline_location_city_24">

    <com.google.android.material.textfield.MaterialAutoCompleteTextView
        android:id="@+id/spinner_country"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:inputType="none" />

</com.google.android.material.textfield.TextInputLayout>
EN

回答 1

Stack Overflow用户

发布于 2022-08-10 16:43:50

您必须检查父主题(在themes.xml文件中),并使用与该主题匹配的样式。在你的情况下,就像:

代码语言:javascript
复制
<style name="Theme.App" parent="Theme.Material3.Dark.NoActionBar">

例如,如果MyApplication具有以下MaterialComponents主题:

代码语言:javascript
复制
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

然后,我必须使用与MaterialComponents的样式匹配:

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

如果我尝试使用Material3样式

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.Material3.TextInputLayout.OutlinedBox">

我也会犯类似的错误。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71037836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档