简体   繁体   English

如何在Android 4.4中制作透明的状态栏?

[英]How to make a transparent status bar in Android 4.4?

I want to make a transparent status bar in my application in Android 4.4. 我想在Android 4.4的应用程序中制作一个透明的状态栏。 How do I do that? 我怎么做?

I tired: 我累了:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/skipPrimary</item>
        <item name="colorPrimaryDark">@color/skipPrimary</item>
        <item name="colorAccent">@color/skipPrimary</item>
    </style>

and in the manifest: 并在清单中:

<application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme" >

and in the activity: 并在活动中:

<activity
            android:name=".activities.StartActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="adjustResize|stateHidden" />

This one will throw exception on Lollipop devices. 这将在Lollipop设备上引发异常。 primColor must be opaque. primColor必须是不透明的。

<item name="primColor">@android:color/transparent</item> 

Style your actionbar using style.xml 使用style.xml栏设置样式

<style name="ThemeActionBar"
        parent="Widget.AppCompat.Light.ActionBar.Solid">
        <item name="android:background">@null</item>
        <!-- Support library compatibility -->
        <item name="background">@null</item>
</style>

Include you theme.. 包括您的主题。

<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>

What you can also do is set the status bar a darker shade of your background or even the same color by setting it in your activity. 您还可以执行以下操作:通过在活动中进行设置,将状态栏设置为较深的背景甚至相同的颜色。

You can set the status bar color in your activity with the following code getWindow().setStatusBarColor(getResources().getColor(R.color.your_color)); 您可以使用以下代码在活动中设置状态栏颜色: getWindow().setStatusBarColor(getResources().getColor(R.color.your_color)); .

If you want to use a darker shade of your color you can do it by changing your color's HSB. 如果要使用较深的颜色,可以通过更改颜色的HSB来实现。 For a more detailed way of doing that you can read this post: Android change status bar color by converting existing color's HSB 有关更详细的操作方法,您可以阅读以下文章: Android通过转换现有颜色的HSB来更改状态栏颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM