android状态栏和导航问题

gkl3eglg  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(437)

最近我在 Main_Activity :

(getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS))

用于状态栏透明目的。一切进展顺利,但我的android导航栏也采用了透明策略。现在我只需要透明的状态栏,而不需要导航栏。

mjqavswn

mjqavswn1#

您有两个选择要做,首先,我建议您使用一个外部库来设置状态栏样式,如statusbarutil库,它使您能够在一行中满足您的需求:

StatusBarUtil.setTransparent(Activity activity) // yo be placed in every activity you want the status bar to be transparent in

这个库不会影响导航栏。
首先确保在应用程序级gradle中实现库:

implementation'com.jaeger.statusbarutil:library:1.5.1'

第二个选项是进行布局自定义,如本教程中所述,您可以将以下内容添加到 style.xml :

<style name="AppTheme.TransparentTheme">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

并将此样式应用于清单中的活动:

<activity
    android:name=".HomeActivity"
    android:theme="@style/AppTheme.TransparentTheme">
</activity>

如本教程所述:
我已经准备好了android:windowdrawssystembarbackgrounds to 是的。
这是一个标志,其描述如下:
指示此窗口是否负责绘制系统栏背景的标志。如果为true且窗口不是浮动的,则系统栏将以透明背景绘制,此窗口中的相应区域将填充{@link android.r.attr#statusbarcolor}和{@link android.r.attr#navigationbarcolor}中指定的颜色。对应于{@link android.view.windowmanager.layoutparams#flag#drawssystembarbackgrounds}。
别忘了添加属性 android:fitsSystemWindows="true" 到活动布局的上根目录。

相关问题