Android开发-状态栏不显示棒棒糖之前(AppCompat)



我正在使用appcompat v21.0.3开发我的应用程序,并在API 21 android ver 5.0.1上进行测试。今天我决定在安卓4.4.2的平板电脑上测试这个应用程序,一切都没问题,但我注意到状态栏变得透明了,掉到了工具栏上。我附上了图片,希望得到你的帮助。附:对不起,我的英文不好,我用谷歌翻译使这篇文章:)

看起来是这样的https://i.stack.imgur.com/W4Sve.png应该是这样的https://i.stack.imgur.com/fR1B7.jpg

在清单中替换

android:theme="@style/AppTheme"

android:theme="@style/Theme.AppCompat.Light.NoActionBar"

使用下面的代码你的主活动分配颜色的状态栏。

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = this.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(this.getResources().getColor(R.color.main_red_dark));
        }

当然,这只是一种方式。我不是100%确定,你实际上是在改变状态栏的代码。这是必须的

将此代码添加到app style.xml中。

   

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorPrimary">@color/primarycolor</item>
    <item name="android:textSize">24sp</item>
    <item name="android:actionBarTabStyle">@color/Textcolor</item>

</style>

最新更新