简体   繁体   中英

AppCompatSpinner throwing InflateException on only few devices

Two days i was stuck with IllegalArgument Exception(given the crash log below) while clicking on the custom AppCompatSpinner. This issue is not happening in all devices, only few devices(Samsung, Oneplus) affected. App themes are listed below for all the api version

parent="Theme.AppCompat.NoActionBar"

v23 theme:

parent="Theme.AppCompat.Light.NoActionBar"

v21 theme:

parent="Theme.MaterialComponents.DayNight.NoActionBar"

My crash log:

E/AndroidRuntime: FATAL EXCEPTION: main
        android.view.InflateException: Binary XML file line #95: Binary XML file line #37: Error inflating class Button
        Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class Button
        Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

Please give some insights to fix this issue. Found some solutions in stackoverflow & other sites but nothing helped me to fix the issue

If you want to use Material UI elements, then

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> should be changed to <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> .

As the error itself is saying, your app theme must be a child of MaterialTheme or any child of the same.

How to build a material theme

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM