0%

安卓设置沉浸式标题栏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
1.在项目目录res/values/themes,修改为:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.HtGasDetection" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
<!-- 主色 -->
<item name="colorPrimary">@color/common_primary_color</item>
<item name="colorPrimaryVariant">@color/common_primary_dark_color</item>
<item name="colorOnPrimary">@color/common_text_color</item>

<!-- 状态栏透明 -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<!-- 内容延伸到状态栏 -->
<item name="android:fitsSystemWindows">false</item>

<!-- 可选:导航栏透明 -->
<item name="android:navigationBarColor">@android:color/transparent</item>

<!-- 默认文本颜色 -->
<item name="android:textColor">@color/common_text_color</item>
<item name="android:textSize">14sp</item>

<!-- 状态栏字体 -->
<item name="android:windowLightStatusBar">true</item>

</style>

<style name="Theme.HtGasDetection" parent="Base.Theme.HtGasDetection" />
</resources>
2.在AndroidManifest.xml中的application标签中设置:
android:theme="@style/Theme.HtGasDetection"
android:forceDarkAllowed="false"