Android集成Stripe支付时遇Theme.AppCompat/MaterialComponents主题错误
解决Stripe集成时"Theme isn't set to use Theme.AppCompat or Theme.MaterialComponents"错误
核心问题是你自定义主题时覆盖了系统自带的Theme.AppCompat名称,Stripe SDK检测主题时会查找系统原生的AppCompat/MaterialComponents主题分支,而你自定义的Theme.AppCompat继承自Theme.SplashScreen,并非SDK要求的主题链,导致识别失败。同时还有几处主题配置不一致的问题需要修正。
解决方案步骤
- 重命名自定义启动屏主题:避免和系统主题重名,防止SDK混淆
- 修正主题引用链路:确保Activity、Application及Flutter关联主题都指向正确的MaterialComponents/AppCompat分支
- 清理重建项目:清除缓存确保配置生效
修改后的styles.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 补充完整缺失的LaunchTheme定义 --> <style name="LaunchTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <item name="android:windowBackground">@drawable/launch_background</item> <item name="android:windowFullscreen">false</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowActionBar">false</item> </style> <!-- 应用核心主题(继承MaterialComponents分支) --> <style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.NoActionBar"> <item name="colorPrimary">@color/primaryColor</item> </style> <!-- 启动屏主题:重命名避免和系统Theme.AppCompat冲突 --> <style name="Theme.Splash" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/primaryColor</item> <item name="windowSplashScreenAnimatedIcon">@drawable/splash_inset</item> <!-- 启动完成后切换到核心主题 --> <item name="postSplashScreenTheme">@style/Theme.MyApp</item> </style> <!-- Flutter Normal主题:确保继承MaterialComponents分支 --> <style name="NormalTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <item name="android:windowBackground">?android:colorBackground</item> </style>
修改后的AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="你的包名"> <!-- Permissions --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- Application Details --> <application android:name="${applicationName}" android:label="Life Italy" android:theme="@style/Theme.MyApp" android:icon="@mipmap/ic_launcher"> <!-- Main Activity --> <activity android:name=".MainActivity" android:exported="true" <!-- 使用重命名后的启动屏主题 --> android:theme="@style/Theme.Splash" android:windowSoftInputMode="adjustResize"> <!-- Flutter Normal主题指向修正 --> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" /> <!-- Main Activity Intent Filter --> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Flutter Embedding Metadata --> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> <!-- Queries for Process Text Intent --> <queries> <intent> <action android:name="android.intent.action.PROCESS_TEXT" /> <data android:mimeType="text/plain" /> </intent> </queries> </manifest>
修改完成后,执行Clean Project -> Rebuild Project清除缓存,重新运行项目即可解决Stripe的主题检测错误。
内容的提问来源于stack exchange,提问作者Omar Dak
相关产品推荐
相关产品推荐

