【问题标题】:How to show splash activity in fullscreen with transparent status bar如何使用透明状态栏全屏显示启动活动
【发布时间】:2017-09-01 14:32:15
【问题描述】:

如何显示带有背景图像的完整初始屏幕以及我想显示状态栏背景有什么活动。

以下启动活动具有完整的图像,它可能会在未来发生变化,现在我做了 iugaad 来显示状态栏背景,但每当我改变我的图像状态栏背景时,应该是那个图像。

Splash Screen

【问题讨论】:

标签: android splash-screen


【解决方案1】:

您需要执行以下步骤,

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">

现在只需转到您的活动并在 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);
}

立即运行,输出将是这样的,

【讨论】:

  • 有效!你把它表达得很透明;)为盟友竖起大拇指。
  • 太棒了!注意,可能需要包含所需的“import android.view.Window/import android.view.View;”行(我来自 react-native,所以不熟悉 Java 编码!)
猜你喜欢
  • 2017-09-16
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-10
  • 2020-02-16
  • 1970-01-01
相关资源
最近更新 更多