隐藏启动屏幕上的通知栏 API 31

发布于 2025-01-14 12:12:03 字数 335 浏览 6 评论 0原文

是否可以使用新的 Android 12 启动屏幕 API 隐藏启动屏幕上的通知栏?这样,当用户启动应用程序时,通知栏就会隐藏。

我尝试将其添加到我的 Theme.SplashScreen

<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

但它似乎没有做任何事情。

Is it possible to hide the notification bar on splash screen with the new Android 12 Splash screen API? So that the notification bar would be hidden from the very moment when the user launches an app.

I tried adding this to my Theme.SplashScreen

<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

but it doesn't seem to do anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二智少女猫性小仙女 2025-01-21 12:12:03

我认为你不能。我还尝试了所有不同的方法,包括:

1. SplashScreen 主题

<style name="Theme.SplashScreen.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#FFFFFF</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launch</item>
    <item name="windowSplashScreenAnimationDuration">5000</item>
    <item name="postSplashScreenTheme">@style/Theme.ComposeDemos</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>

2. Android 建议的隐藏状态栏的代码

// onCreate
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()

// and
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.hide(WindowInsets.Type.statusBars())
} else {
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN)
}

没有任何效果。代码部分仅影响第一个活动,而不影响启动屏幕。

我认为您能做的最接近的事情就是创建一个闪屏活动,而不是使用 SplashScreen API。

I don't think you can. I've also tried all different methods including :

1. SplashScreen Theme

<style name="Theme.SplashScreen.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#FFFFFF</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launch</item>
    <item name="windowSplashScreenAnimationDuration">5000</item>
    <item name="postSplashScreenTheme">@style/Theme.ComposeDemos</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>

2. Code for hiding status bar suggested by Android

// onCreate
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()

// and
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.hide(WindowInsets.Type.statusBars())
} else {
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN)
}

nothing works. The code parts only affects the first Activity and not Splash Screen.

I think the closest you can do is to create an Splash screen activity instead of using SplashScreen API.

故人如初 2025-01-21 12:12:03
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

将以上代码放入 Splash Screen 活动的 onCreateMethod 中。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Put above code in onCreateMethod of the activity of Splash Screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文