Widget.Material3 TextAppearance属性错误



当从材质样式中使用此样式时,无论我在AppTheme中在哪里提供TextAppearance,还是扩展该样式本身并提供TextAppAppearance

应用程序崩溃,出现以下错误:

E/AndroidRuntime:由:java.lang.IollegalArgumentException引起:此组件要求指定有效的TextAppearance属性。更新应用程序主题以从theme.MaterialComponents(或子代(继承。网址:com.google.android.material.internal.ThemeEnforcement.checkTextAppearance(ThemeEncement.java:185(网址:com.google.android.material.internal.ThemeEnforcement.ugetableIntedStyledAttributes(ThemeEncement.java:116(网址:com.google.android.material.textfield.TextInputLayout.(TextInputLayout.java:474(网址:com.google.android.material.textfield.TextInputLayout.(TextInputLayout.java:433(

XML组件如下所示

<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>

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

<style name="Theme.App" parent="Theme.Material3.Dark.NoActionBar">

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

<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

然后我必须使用与材料组件匹配的样式:

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

如果我尝试使用Material3风格的

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox">

我也会有类似的错误。

相关内容

  • 没有找到相关文章

最新更新