1

I have an Activity which shows contact details of a person. it contains CordinatorLayout (containing header), ViewPager in it along with TabLayout.

one of the fragment contains EditText at the bottom which is contained in ViewPager.

I'm using the following theme for this activity. `

    <style name="ToolbarAppThemeV4WithoutActionBar" parent="ToolbarAppThemeV4">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
        <item name="colorPrimary">@color/colorPrimaryDesignV4</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:textColorPrimary">@color/color_v4_primary</item>
        <item name="android:actionMenuTextColor">@color/white</item>
        <item name="android:textColorSecondary">@color/color_v4_secondary</item>
        <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
        <item name="alertDialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="actionModeBackground">@color/color_multiselectTopBarbackground</item>
        <item name="actionModeCloseDrawable">@drawable/in_ic_back_white</item>
        <item name="actionModeStyle">@style/SomeStyle</item>
        <item name="popupMenuStyle">@style/PopupmenuV4</item>
        <item name="colorAccent">@color/colorPrimaryDesignV4</item>
        <item name="android:windowTranslucentStatus">true</item>
    <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
    </style>

`

I'm trying to use android:windowSoftInputMode="adjustPan" and "adjustResize" and every possible combinations but it is not showing properly.

Please assume that following fragment screen is displayed in ViewPager. Actual result:

enter image description here

Expected result:

enter image description here

Can anyone help me in this? I tried every possible combination in activity's windowSoftInputMode in manifest. but nothing is working.

Please note that the If I use the same fragment in different activity, it is working. tried to use same theme but it is not working in this activity.

Is it something related to ViewPager, Fragment, Cordinator Layout? Please help me in this.

XML layout which contains EditText input field: `

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/white"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp">

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

        <ImageView
            android:id="@+id/toolbar_back"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="4dp"
            android:layout_marginStart="4dp"
            android:background="?android:attr/actionBarItemBackground"
            android:scaleType="center"
            android:src="@drawable/in_ic_back_red" />

        <TextView
            android:id="@+id/comments_toolbar_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_toEndOf="@+id/toolbar_back"
            android:layout_toRightOf="@+id/toolbar_back"
            android:textColor="@color/colorPrimaryDesignV4"
            android:textSize="@dimen/font_size_text_medium" />

        <View
            style="@style/HorizontalDividerV4"
            android:layout_alignParentBottom="true" />

    </RelativeLayout>

</android.support.v7.widget.Toolbar>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottom_bar"
    android:layout_below="@+id/toolbar">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        tools:visibility="visible">

        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="10dp"
            android:indeterminate="true" />

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/master_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

        <!--contains loader, error or empty states-->
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />


        <android.support.design.widget.CoordinatorLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="8dp"
            android:orientation="vertical"
            android:padding="3dp"
            android:scaleType="centerInside">

            <RelativeLayout
                android:id="@+id/fab"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_marginBottom="5dp"
                android:layout_marginEnd="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginStart="5dp"
                android:layout_marginTop="12dp"
                android:background="@drawable/rounded_circle_fab"
                android:elevation="3dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@drawable/in_ic_img_down_red_svg" />

            </RelativeLayout>

            <TextView
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/rounded_circle_green"
                android:elevation="3dp"
                android:foregroundGravity="top"
                android:gravity="center"
                android:textColor="@color/white"
                android:textSize="@dimen/font_size_text"
                android:textStyle="bold"
                android:visibility="gone"
                app:layout_anchor="@id/fab"
                app:layout_anchorGravity="top|center_horizontal"
                tools:text="4"
                tools:visibility="visible" />

        </android.support.design.widget.CoordinatorLayout>

    </FrameLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        tools:visibility="visible">

        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="10dp"
            android:indeterminate="true" />

    </RelativeLayout>

</RelativeLayout>

<FrameLayout
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/white"
    android:paddingTop="6dp">

    <View style="@style/HorizontalDividerV4" />

    <RelativeLayout
        android:id="@+id/actions_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:background="@color/white">

        <ViewFlipper
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

            <ImageView
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:scaleType="center"/>

            <ImageView
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:scaleType="centerInside"/>

        </ViewFlipper>

        <View
            android:id="@+id/vertical_divider"
            android:layout_width="1dp"
            android:layout_height="36dp"
            android:layout_centerVertical="true"
            android:background="@color/color_divider_v4" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@color/white"
            android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
            android:maxLines="3"
            android:minLines="1" />

        <ViewFlipper
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true">

            <ImageView
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:scaleType="centerInside"/>

            <ImageView
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:scaleType="centerInside" />

        </ViewFlipper>

        <View
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_margin="6dp"
            android:background="@drawable/rounded_circle_green"
            android:visibility="gone"
            tools:visibility="visible" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_marginTop="1dp"
        android:background="@color/light_green_v4_bg"
        android:gravity="center"
        android:visibility="gone"
        tools:visibility="gone">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/color_v4_secondary"
            android:textSize="@dimen/font_size_text"/>

    </LinearLayout>

</FrameLayout>

</RelativeLayout>`
Jay Patel
  • 486
  • 1
  • 4
  • 14
  • use this inside onCreateView `getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); ` – Mohammed Farhan Mar 13 '18 at 09:34
  • 4
    Possible duplicate of [Layout is not floating above keyboard in Fragment in Android](https://stackoverflow.com/questions/48677901/layout-is-not-floating-above-keyboard-in-fragment-in-android) – AskNilesh Mar 13 '18 at 09:36

2 Answers2

2

android:windowSoftInputMode="adjustPan is work this way . What you need is android:windowSoftInputMode="adjustResize" .

Try to set it at runtime in fragment and change it as per your need .

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
ADM
  • 20,406
  • 11
  • 52
  • 83
  • It should work . MayBe something wrong with your layout add your layout in question . – ADM Mar 14 '18 at 12:13
  • is it something related to view hierarchy? because the edit text is contained in one fragment which is in another fragment, which is in turn contained in ViewPager, and finally Activity comes into picture at last. – Jay Patel Mar 14 '18 at 12:29
  • If `Edittext` exist in fragment Make your fragment Root as `RelativeLayout` and set the `SoftInputMode` in `Fragment` – ADM Mar 14 '18 at 12:32
  • let me try this – Jay Patel Mar 14 '18 at 12:34
  • that is already in RelativeLayout and tried to set it run time, but not working. Do I need to make the whole view hierarchy such this? – Jay Patel Mar 14 '18 at 13:01
  • I can not say right now. I have no idea of your Components hierarchy . Add the code and xml in question . – ADM Mar 14 '18 at 13:03
  • the whole code is too big. and Hierarchy is -> Activity -> ViewPager -> Fragment -> Fragment -> (RelativeLayout - EditText) – Jay Patel Mar 14 '18 at 13:14
  • Ok add the layout of last `Fragment` i'll have a look . – ADM Mar 14 '18 at 13:16
  • Added in Q. please check – Jay Patel Mar 14 '18 at 13:24
  • This doesn't seems the layout of the GIF you have attached . Why `Toolbar` is your outer root . This does not make any sense to me . Anyway As i said earlier make a `RelativeLayout` as root and align `EditText` to bottom inside it . – ADM Mar 14 '18 at 13:55
  • above layout is for sample, not actual layout. that was just to show the scenario – Jay Patel Mar 15 '18 at 04:43
0

Try :

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);