【问题标题】:color the statusbar in android splash screen在android启动画面中为状态栏着色
【发布时间】:2016-05-10 13:37:39
【问题描述】:

我在我的 Android 应用中添加了一个启动画面,我想在显示时给状态栏一个颜色。

这是drawable下文件的内容:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/colorPrimary" />

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_home"/>
    </item>

</layer-list>

我添加了这种风格:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splashscreen</item>
</style>

【问题讨论】:

    标签: android splash-screen


    【解决方案1】:

    colorPrimaryDark 项目添加到您的主题应该可以解决问题:

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splashscreen</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    </style>
    

    【讨论】:

    • 如果您有 2 个styles.xml,则需要在 res\values-v21\styles.xml 中完成此操作,而另一个 res\values\styles.xml 用于较旧的 android 版本。
    • 您可以在res\values\styles.xml 中设置它,因为colorPrimaryDark 在旧设备上将被忽略。对于作为初始屏幕主题的简单主题,我更喜欢保持简单。
    • 您还可以添加 @color/colorPrimary,这样如果用户最小化应用程序,您就会显示您喜欢的应用程序标题颜色。
    【解决方案2】:
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    }
    

    【讨论】:

      【解决方案3】:

      插入themes.xml & temes.xml(night):

      <item name="colorPrimaryVariant">@color/black</item>
      

      【讨论】:

        【解决方案4】:

        在您当前的启动主题中添加 colorPrimaryDark 项目,在 styles.xml 中:

        <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="colorPrimaryDark">@color/statusbar_bg</item>
        </style>
        

        如果你为状态栏选择了浅色,你可以添加:

        <item name="android:windowLightStatusBar">true</item>
        

        在colors.xml里面ressources添加:

        <color name="statusbar_bg">#FFFFFF</color>
        

        然后在 MainActivity.java 中显示 SplashScreen 时将其用作第二个参数:

        public class MainActivity extends ReactActivity {
        
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                SplashScreen.show(this, R.style.SplashTheme);
                super.onCreate(savedInstanceState);
            }
        }
        

        【讨论】:

          猜你喜欢
          • 2017-11-05
          • 2015-11-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-17
          • 2021-05-30
          • 2016-05-18
          • 1970-01-01
          相关资源
          最近更新 更多