如何使用透明状态栏在全屏幕中显示启动活动

tne*_*han 6 android splash-screen

如何使用背景图像显示完整的启动画面,我还想显示状态栏背景的活动.

以下启动活动有完整的图像它将来可能会改变,现在我做iugaad显示状态栏背景,但每当我改变我的图像状态栏背景应该该图像.

启动画面

Muk*_*esh 14

你需要做以下步骤,

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>
Run Code Online (Sandbox Code Playgroud)

注意:在没有v21代码的情况下添加上面的样式styles.xml

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

 android:theme="@style/AppTheme.NoActionBar">
Run Code Online (Sandbox Code Playgroud)

现在只需转到您的活动并在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);
}
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述