繁体   English   中英

Android状态栏和导航问题

[英]Android Status bar and Navigation issues

最近,我在Main_Activity使用了以下Java代码:

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

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

您有两种选择,第一种,我建议您使用状态库样式的外部库,例如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设置为true。

这是一个标志,其描述如下:

指示此Window是否负责绘制系统栏背景的标志。 如果为true且窗口未漂浮,则系统栏将以透明背景绘制,并且该窗口中的相应区域将填充{@link android.R.attr#statusBarColor}和{@link android.R中指定的颜色.attr#navigationBarColor}。 对应于{@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS}。

不要忘记将android:fitsSystemWindows="true"属性添加到活动布局的顶部。

暂无
暂无

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

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