You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 02:55:10