Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content goes behind soft navigation bar for api 21 and up

Have upgraded app to use Material Design - Theme.AppCompat.Light.NoActionBar, Toolbar instead of ActionBar etc..

And have a problem. Bottom content become to be hidden under soft NavigationBar (see picture below) on devices with APi >= 21

Have found solution to fix this:

in values-v21/styles.xml

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <item name="colorPrimaryDark">@color/green</item>
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</styles>

if option <item name="android:windowDrawsSystemBarBackgrounds">false</item> - bottom content is visible, but statusbar become completely black. I cant change color to colorPrimaryDark (green in my case)

if option <item name="android:windowDrawsSystemBarBackgrounds">true</item> - bottom content is invisible, and statusbar is green, as expected.

I want to have statusbar colored(green) and visible bottom content.. Probably, issue is with toolbar. Is it pushes content down?

Any suggestions?

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

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

UPDATE:

As suggested @azizbekian, I've replaced container for fragmets to CoordinatorLayout(before FrameLayout) and applied android:fitsSystemWindows="true" In this case bottom panel is visible, but not at the bottom.. Goal is to keep buttons athe bottom...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              android:orientation="vertical">
    <include
        layout="@layout/toolbar"/>

        <!-- The main content view -->
        <android.support.design.widget.CoordinatorLayout
                android:id="@+id/content"
            android:fitsSystemWindows="true"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
</LinearLayout>

layout of the screen:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <FocusableScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/order_editor_layout"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                layout="@layout/o_e_content" 
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"/>
        </RelativeLayout>
    </FocusableScrollView>
    <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/oe_bottom_pane"/>
</LinearLayout>

Here is result:

UPDATE#2

Activity Layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ActionBarTheme"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <!-- The main content view -->
        <FrameLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>

Replaced LinearLayour with CoordinatorLayout as root for activity. As root element for content I've keep FrameLayout. Applied android:fitsSystemWindows="true" to CoordinatorLayout. This way, all content was slightly moved up and part of placed below the toolbar(you can see on image below - top elements are circle with + and - symbold. But on previous images there are text on the top.) Regarding bottom elements (buttons panel) - still placed below navigation bar but also slightly moved up. I've marked android:background="@color/red" to easier recognize position of this panel.

Seems, we are on the right way. All we need - to resolve problem - why content moved below the toolbar.. If tolbar will be top ui elemnt, buttons will be visible..

like image 519
vsvydenko Avatar asked Oct 30 '22 03:10

vsvydenko


1 Answers

Apply android:fitsSystemWindows="true" to your root view.

See this post for detailed explanation.

like image 129
azizbekian Avatar answered Nov 15 '22 05:11

azizbekian