Android 完全透明的状态栏?

2024-01-05

I've searched the documentation but only found this: Link http://developer.android.com/about/versions/android-4.4.html#UI. Which is used to make the bar translucent? What I'm trying to do is to make the status bar completely transparent (as shown in the image below) and make it backwards compatible for APK<19: enter image description here

我的styles.xml:

<resources xmlns:tools="http://schemas.android.com/tools">

  <style name="AppTheme" parent="Theme.AppCompat.Light">
  <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>
  </style>

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

  </style>

</resources>

我能做什么:


您需要做的就是在主题中设置这些属性:

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

您希望具有透明状态栏的活动/容器布局需要设置此属性:

android:fitsSystemWindows="true"

通常不可能在 pre-kitkat 上执行此操作,看起来你可以做到但一些奇怪的代码使得它如此 https://stackoverflow.com/questions/21865621/transparent-status-bar-before-4-4-kitkat.

编辑:我会推荐这个库:https://github.com/jgilfelt/SystemBarTint https://github.com/jgilfelt/SystemBarTint用于很多预棒棒糖状态栏颜色控制。

经过深思熟虑,我了解到完全禁用棒棒糖状态栏和导航栏上的半透明或任何颜色的答案是在窗口上设置此标志:

// In Activity's onCreate() for instance
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    Window w = getWindow();
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

不需要其他主题,它会产生如下内容:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 完全透明的状态栏? 的相关文章

随机推荐