Display content behind state and navigation bar

This seems like a duplicate question, but I can't do it. I want a completely transparent (not translucent) status bar, as well as a navigation bar, and want the content to appear behind them.

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>

In action java file

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

This is what I get.

enter image description here

How to get content from the navigation bar?

If I add

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

to my styles.xml

This is what i get

enter image description here

As you can see, the content extends beyond the navigation bar, but for this the navigation bar must be translucent.

Is there any solution for this?

+2
source share
1 answer

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 , - , FULLSCREEN , ( ). . LAYOUT_NO_LIMIT , .

, .

API ViewCompat.setOnApplyWindowInsetListener , android:fitsSystemWindows="true", . .

ViewCompat.setOnApplyWindowInsetsListener(toolbar, (v, insets) -> {
    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
    params.topMargin = insets.getSystemWindowInsetTop();
    return insets.consumeSystemWindowInsets();
});

, FrameLayout, LinearLayout RelativeLayout, , (, DrawerLayout, CoordinatorLayout). , , . onApplyWindowInsets.

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    int childCount = getChildCount();
    for (int index = 0; index < childCount; ++index)
        getChildAt(index).dispatchApplyWindowInsets(insets); 
        // let children know about WindowInsets

    return insets;
}

: OnApplyWindowInsetsListener, WindowInsets

+8

Source: https://habr.com/ru/post/1650732/


All Articles