1

I have a fragment for user input,when the keyboard appears my fragment screen is shifting even above status bar and tool bar.

Without keyboard - https://www.dropbox.com/s/51gygn8z768bkp0/Screenshot_2015-10-01-15-26-37.png?dl=0

With Keyboad - https://www.dropbox.com/s/z88pegbn7a0qoht/Screenshot_2015-10-01-15-26-44.png?dl=0

screen shot of this problem can be seen in above share image urls. I am trying to use Translucent screen for app.

My activity layout is -

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!--<LinearLayout
        android:id="@+id/container_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">-->

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
    <!-- </LinearLayout>-->

    <FrameLayout
        android:id="@+id/container_body"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" />


</LinearLayout>


<fragment
    android:id="@+id/fragment_navigation_drawer"
    android:name="com.pace.automate.fragment.FragmentDrawer"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"
    tools:layout="@layout/fragment_navigation_drawer" />

and the theme i am using for app is

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:typeface">monospace</item>

    </style>

and tool bar is like -

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

which has the property fitsSystemWindows =true. but layout is shifting up,even i have tried to put fragment layout inside the scroll view and set the android:windowSoftInputMode="adjustPan" in manifest for this activity.but still screen it pushing upside when keyboard appears. my fragment layout is like

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:customAttrs="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



     <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            >
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp">


                <com.pace.automate.Utils.CustomFonts
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="16dp"
                    android:text="Please fill the Details"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#898989"
                    customAttrs:customFont="regular" />

                <EditText
                    android:id="@+id/amount"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/title"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="12dp"
                    android:background="@android:color/transparent"
                    android:drawableBottom="@drawable/log_entry_keyline"
                    android:drawableLeft="@drawable/log_entry_icn_amount"
                    android:drawablePadding="7dp"
                    android:ems="10"
                    android:hint="Amount"
                    android:inputType="numberDecimal"
                    android:padding="4dp">

                    <requestFocus />
                </EditText>

                <EditText
                    android:id="@+id/odometer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/amount"
                    android:layout_marginTop="12dp"
                    android:background="@android:color/transparent"
                    android:drawableBottom="@drawable/log_entry_keyline"
                    android:drawableLeft="@drawable/log_entry_icn_odometer"
                    android:drawablePadding="7dp"
                    android:ems="10"
                    android:hint="Odometer Reading"
                    android:inputType="number"
                    android:padding="4dp">


                </EditText>

                <EditText
                    android:id="@+id/liters"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/odometer"
                    android:layout_marginTop="12dp"
                    android:background="@android:color/transparent"
                    android:drawableBottom="@drawable/log_entry_keyline"
                    android:drawableLeft="@drawable/measurement_volume_icon"
                    android:drawablePadding="7dp"
                    android:ems="10"
                    android:hint="Liters"
                    android:inputType="numberDecimal"
                    android:padding="4dp" />

                <TextView
                    android:id="@+id/calendar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/liters"
                    android:layout_marginTop="12dp"
                    android:drawableBottom="@drawable/log_entry_keyline"
                    android:drawableLeft="@drawable/log_entry_icn_calendar"
                    android:drawablePadding="7dp"
                    android:ems="10"
                    android:hint="Date"
                    android:inputType="date"
                    android:padding="4dp"
                    android:textSize="16dp" />

                <CheckBox
                    android:id="@+id/fulltank"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/calendar"
                    android:layout_marginLeft="35dp"
                    android:layout_marginTop="20dp"
                    android:button="@drawable/custom_chekbox_fuel_enter"
                    android:paddingLeft="4dp"
                    android:text="Full Tank" />

                <CheckBox
                    android:id="@+id/partialtank"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/fulltank"
                    android:layout_alignBottom="@+id/fulltank"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="35dp"
                    android:button="@drawable/custom_chekbox_fuel_enter"
                    android:checked="true"
                    android:paddingLeft="4dp"
                    android:text="Partial Tank" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/partialtank"
                    android:layout_marginTop="12dp">

                    <com.pace.automate.Utils.CustomAutoComplete
                        android:id="@+id/tag_station"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_toLeftOf="@+id/pb_loading_indicator"
                        android:background="@android:color/transparent"
                        android:drawableBottom="@drawable/log_entry_keyline"
                        android:drawableLeft="@drawable/log_entry_icn_tag_station"
                        android:drawablePadding="7dp"
                        android:ems="10"
                        android:hint="Tag your Fuel station"
                        android:padding="4dp" />

                    <ProgressBar
                        android:id="@+id/pb_loading_indicator"
                        style="?android:attr/progressBarStyleSmall"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center_vertical|right"
                        android:layout_marginRight="2dp"
                        android:visibility="gone" />
                </RelativeLayout>


            </RelativeLayout>
        </ScrollView>

        <Button
            android:id="@+id/saveFuelLogs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="12dp"
            android:background="#4cc1bb"
            android:text="Save"
            android:textColor="#fff"
            android:textSize="@dimen/button_text_size" />

    </RelativeLayout>

please help me in this ,It's seems very basic mistake i am doing here but couldn't able to short it out.

Toolbar overlapping below status bar

Fragment overlaps my AppCompat toolbar

tried similar kind of above suggestion but still no solution found.

also manifest have android:windowSoftInputMode="adjustPan" for this activity.

Community
  • 1
  • 1
Anshul Kabra
  • 129
  • 17

2 Answers2

0

If your app is above 21 api level you can use following code, but you have to first detect if keyboard is displaying or not.

hideStatusBar(true); to hide or hideStatusBar(false); to show

public static void hideStatusBar(boolean isHide) {
    final View decorView = UnationApplication.getInstance().getActivity().getWindow().getDecorView();

    final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    if (isHide) {
        int flagsMore = flags | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        decorView.setSystemUiVisibility(flagsMore);
    } else {
        decorView.setSystemUiVisibility(flags);
    }

    decorView
            .setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

                @Override
                public void onSystemUiVisibilityChange(int visibility) {
                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                        //  decorView.setSystemUiVisibility(flags);
                    }
                }
            });
}
KumailR
  • 505
  • 1
  • 4
  • 20
-1

Try removing fitSystemWindows= "true"

user2453055
  • 975
  • 1
  • 9
  • 19