gpt4 book ai didi

android - 如何使用透明状态栏全屏显示启动 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:59:22 24 4
gpt4 key购买 nike

我如何显示带有背景图像的完整启动画面以及我想显示状态栏背景有什么 Activity 。

以下启动 Activity 有完整图像,将来可能会更改,现在我做了 iugaad 来显示状态栏背景,但每当我更改我的图像状态栏背景时,应该显示该图像。

Splash Screen

最佳答案

您需要执行以下步骤,

v21/styles.xml

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorStatusBarColor</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>

<!--Required Api 21 above-->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

</style>

注意:styles.xml

中添加无v21代码的上述样式

AndroidManifest.xml 中应用该样式作为 `android:theme

 android:theme="@style/AppTheme.NoActionBar">

现在只需转到您的 Activity 并在 onCreate 方法中添加以下代码行,

private Window mWindow;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

mWindow = getWindow();
mWindow.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

现在运行 & 输出将是这样的,

enter image description here

关于android - 如何使用透明状态栏全屏显示启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46002530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com