2017-08-05 53 views
2

这看起来像一个重复的问题,但我无法做到。我想要完整的透明(不是半透明)状态栏以及导航栏,并希望内容出现在它们后面。显示状态和导航栏背后的内容

activity_details.xml

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorPrimary" 
    tools:context="com.bitspilanidvm.bosm2017.DetailsActivity"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/q" 
    android:scaleType="centerCrop"/> 

</LinearLayout> 

V21 styles.xml

<resources> 

<!-- Theme for API level > 21 --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!--Customize your theme here. --> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
    <item name="android:navigationBarColor">@android:color/transparent</item> 
</style> 

在活动的java文件

getWindow().getDecorView().setSystemUiVisibility(
     View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
       View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
     ); 

这是我得到的。

enter image description here

如何获得导航栏后面的内容?

如果我添加

<item name="android:windowTranslucentNavigation">true</item> 

我styles.xml

这里是我所得到的

enter image description here

正如你所看到的,内容云的背后导航栏,但导航栏必须是半透明的。

有没有解决方案?

+0

不错这个设备有没有硬背按钮? –

回答

7

在窗口中添加FLAG_LAYOUT_NO_LIMITS标志。这将适用于Android KitKat和以上的API。这个例子是这样的:

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

之所以FLAG_FULLSCREEN不工作很简单,因为全屏标志是去除屏幕花色像状态栏(它为你的作品)。但导航栏不是屏幕装饰。 LAYOUT_NO_LIMIT标志允许窗口延伸超出屏幕限制,因此导航栏也被覆盖在该标志内。

此外,您可以通过在沉浸模式下设置应用程序来隐藏导航和状态栏。

+0

谢谢!它工作完美。请你简单解释一下为什么如此?为什么要将装饰视图系统UI可见性标志设置为View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN不起作用? –

+1

FLAG_FULLSCREEN不起作用的原因很简单,因为FULLSCREEN标志用于移除状态栏(适用于您)的屏幕装饰。但导航栏不是屏幕装饰。 LAYOUT_NO_LIMIT标志允许窗口超出屏幕限制,因此导航栏也被覆盖在该标志内。 – Abhi

+0

如果答案解决了问题,请点击答案旁边的勾号图标接受答案。 – Abhi