0

两天后,我在单击自定义 AppCompatSpinner 时遇到了 IllegalArgument 异常(鉴于下面的崩溃日志)。此问题并非在所有设备中都发生,只有少数设备(三星、一加)受到影响。下面列出了所有 api 版本的应用程序主题

parent="Theme.AppCompat.NoActionBar"

v23 主题:

parent="Theme.AppCompat.Light.NoActionBar"

v21 主题:

parent="Theme.MaterialComponents.DayNight.NoActionBar"

我的崩溃日志:

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

请提供一些见解以解决此问题。在 stackoverflow 和其他站点中找到了一些解决方案,但没有任何帮助我解决问题

4

1 回答 1

0

如果你想使用 Material UI 元素,那么

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">应改为<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">.

正如错误本身所说,您的应用程序主题必须是MaterialTheme相同的孩子或任何孩子。

如何构建材质主题

于 2021-02-27T13:53:58.203 回答