安装BarcodeScanner.Mobile 8.0.0.1后MAUI启动抛Java异常求助
解决MAUI安装BarcodeScanner.Mobile 8.0.0.1后的主题异常问题
安装BarcodeScanner.Mobile 8.0.0.1后,MAUI安卓端启动时出现以下异常:
MAUI 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).'
这个问题很常见,原因是该版本的扫码库依赖Material Components组件,而你的应用当前主题未继承MaterialComponents系列主题,导致组件无法找到必需的TextAppearance属性。
解决步骤:
- 打开MAUI项目的安卓部分,找到
Resources/values/styles.xml文件 - 修改主题的父类为MaterialComponents的派生主题,比如将原有主题:
<style name="MainTheme" parent="Theme.Maui.Light">
替换为:
<style name="MainTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
- 确认
AndroidManifest.xml中已正确应用该主题,比如:
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:theme="@style/MainTheme">
如果你的项目使用了自定义主题,只要确保父主题是Theme.MaterialComponents或其任意子类即可,比如Theme.MaterialComponents.Light.NoActionBar等,根据你的UI需求选择合适的主题。
内容的提问来源于stack exchange,提问作者Rajzer
相关产品推荐
相关产品推荐

