Android Studio applying splash给予me error您需要在此Activity中使用Theme.AppCompat主题(或子主题

kokeuurv  于 11个月前  发布在  Android
关注(0)|答案(9)|浏览(142)

在23中,我们默认定义了这些样式,现在我必须开始全屏飞溅
vlue/stylefile

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

字符串
v21样式文件:

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>


清单:

android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".User_MainInterface"
            android:label="@string/title_activity_user__main_interface"
            android:theme="@style/AppTheme.AppBarOverlay"></activity>


请帮我快速解决这个问题

7vhp5slm

7vhp5slm1#

如果您在为 Android 12 实现新的SplashScreen API时遇到此错误,请不要忘记installSplashScreen

SplashScreen splashScreen = SplashScreen.installSplashScreen(this);

字符串
别忘了在 * setContentView()之前加上这个 *。

bprjcwpo

bprjcwpo2#

万一对任何人都有用。
如果你正在使用androidx.core:core-splashscreen并且出现了这个错误,对我来说,使用Kotlin,有效的方法是:
onCreate方法中,在super.onCreate(savedInstanceState)之前调用installSplashScreen()
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
它应该类似于:

override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        //other methods
}

字符串

ep6jt1vc

ep6jt1vc3#

在style.xml中添加此代码

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

字符串
然后.像这样更新您的飞溅活动清单

<activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

o2gm4chl

o2gm4chl4#

来自Android 12并面临这个问题?这是它与我一起克服异常并隐藏动作栏的唯一方法:

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/ed_colorPrimary</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_logo</item>
    <item name="windowSplashScreenAnimationDuration">200</item>
    
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    
    <item name="android:windowBackground">@color/ed_colorPrimary</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>

字符串

x3naxklr

x3naxklr5#

在实现Splash API(androidx.core:core-splashscreen)后遇到问题的人,请按照以下步骤操作。
定义:

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/ed_colorPrimary</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_logo</item>
    <item name="windowSplashScreenAnimationDuration">200</item>
   <!-- Set the theme of the Activity that directly follows your splash screen. -->
    <!-- Required -->
    <item name="postSplashScreenTheme">@style/Theme.MyAppTheme</item>

</style>

字符串
然后在Manifest中检查并验证您是否给出了Theme.App.Starting

<application
    ...
    android:theme="@style/Theme.App.Starting" > 
    ...
    <activity
        android:name=".ui.MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


最后,别忘了补充。

class MainActivity : BaseActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val splashScreen = installSplashScreen()
        ...

ki0zmccv

ki0zmccv6#

只需将android:theme="@style/AppTheme.NoActionBar"更改为android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"即可实现全屏

6rvt4ljy

6rvt4ljy7#

如果您在为Android 12实现新的SplashScreen API时遇到此错误,请尝试将android:windowBackground添加到postSplashScreenTheme属性,如下所示:

<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
    
    ...
  
    <item name="postSplashScreenTheme">@style/Theme.App</item>
    
</style>

<style name="Theme.App" parent="Theme.Material3.DayNight">
    <item name="android:windowBackground">@color/app_color</item>
</style>

字符串

zsohkypk

zsohkypk8#

我也遇到过类似的问题,尽管我在我的主要活动中正确地调用了installSplashScreen()
然而,我也使用了hilt注入,这意味着我在自动化测试中有一个特别为hilt创建的额外活动。
如果有人遇到了同样的问题,你也需要在那里调用installSplashScreen(),就像你在主活动中所做的那样。
例如:

@AndroidEntryPoint
class HiltActivityForTest : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)
    }
}

字符串

drkbr07n

drkbr07n9#

尝试使用这种风格。

<style name="FullscreenTheme" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

字符串
对于闪屏

相关问题