The app crashes with the following error:
E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant). at 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)
The XML component looks like below
<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>
You must check the parent theme (in themes.xml file) and use a style that matches that theme. In your case, something like:
<style name="Theme.App" parent="Theme.Material3.Dark.NoActionBar">
For instance, if MyApplication has the following MaterialComponents theme:
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
Then I have to use style matching to MaterialComponents:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
If I try to use Material3 style
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox">
I would have a similar error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.