半透明导航,而不布局显示下方状态栏 [英] Translucent navigation without layout displaying beneath status bar

查看:89
本文介绍了半透明导航,而不布局显示下方状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是最新的Andr​​oid 4.4 FLAG_TRANSLUCENT_NAVIGATION 标记打开屏幕半透明的底部导航栏(后退,主页按钮等)。这工作正常,但这样做的副作用是我活动的布局现在显示在屏幕(虽然我还没有设置状态栏是半透明)顶部的状态栏下方。我想避免一个哈克修复即施加填充的布局的顶部。

I am using the new Android 4.4 FLAG_TRANSLUCENT_NAVIGATION flag to turn the navigation bar (back, home button etc) at the bottom of the screen translucent. This works fine but a side effect of this is the layout of my Activity now displays beneath the status bar at the top of the screen (even though I have not set the status bar as being translucent). I want to avoid a hacky fix I.e. applying padding to the top of the layout.

有没有一种方法来设置导航半透明,同时确保状态栏显示正常,不允许布局,以显示它下面?

Is there a way to set the navigation as translucent whilst ensuring the status bar appears normally and does NOT allow the layout to display beneath it?

在code我现在用的就是如下:

The code I am using is as follows:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    Window w = getWindow();
    w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

感谢

推荐答案

ianhanniballake的回答实际工作,但你不应该使用安卓fitsSystemWindows =真正的的顶层视图。此属性如下:

ianhanniballake's answer actually works, but you shouldn't use android:fitsSystemWindows="true" on the toplevel view. Use this property as following :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/colorPrimaryDark">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#ffffff"
        android:fitsSystemWindows="true">

        <!-- Your other views -->

    </LinearLayout>
</LinearLayout>

正如你所看到的,你必须设置在顶层观色,并把财产上的另一个容器。

As you can see, you have to set the color on the top-level view, and put the property on another container.

这篇关于半透明导航,而不布局显示下方状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆