【发布时间】:2022-01-27 00:58:24
【问题描述】:
此代码使状态栏在 Android 10 及之前版本上透明
//makes actionbar transparent activity.window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
但是在 android 11 中它并没有消失
Android 11
Android 8
我的 styles.xml 文件如下所示
<resources xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<style name="DropitTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<!-- color used by navigation icon and overflow icon -->
<item name="colorOnPrimary">@color/colorPrimary</item>
</style>
<style name="Toolbar_text_style" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<!-- color used by navigation icon and overflow icon -->
<item name="android:textSize">@dimen/textSizeHuge</item>
</style>
</resources>
清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/DropitTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>
最后是themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<!-- Base application theme. -->
<style name="Theme.Dropit" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryVariant">@color/colorSecondary</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/colorSecondary</item>
<item name="colorSecondaryVariant">@color/colorSecondaryLight</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
正如您在 Manifest 中看到的,我使用的是样式主题而不是主题主题。那么我该如何解决这个问题呢?
【问题讨论】:
-
您好,我在 Android 11 上遇到了同样的问题。(模拟器 Pixel 4 和物理设备)。您介意将您的
styles.xml或themes.xml文件分享给其他想帮助您的人吗? -
嘿@dumbfingers 感谢您的回复,我添加了您要求的两个文件