虽然从材料样式中使用这种样式,但我在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组件如下所示
<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>发布于 2022-08-10 16:43:50
您必须检查父主题(在themes.xml文件中),并使用与该主题匹配的样式。在你的情况下,就像:
<style name="Theme.App" parent="Theme.Material3.Dark.NoActionBar">例如,如果MyApplication具有以下MaterialComponents主题:
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">然后,我必须使用与MaterialComponents的样式匹配:
<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">我也会犯类似的错误。
https://stackoverflow.com/questions/71037836
复制相似问题