Rajitha Perera
Rajitha Perera

Reputation: 1621

android:fitsSystemWindows not working on Fragment

I have a fragment call reload fragment below. Parent activity is MainActivity. I attached manifest file code which related to activity. When I click in the edittext bottom buttons cover edittext fields with the keyboard. I added android:fitsSystemWindows property in the manifest file. Is there anything missing in my code?

enter image description here

Fragment Layout

    <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout 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:fitsSystemWindows="true"
            android:layout_height="match_parent"
            android:background="@drawable/fragments_background"
            tools:context=".ui.fragments.BillPaymentFragment">

            <LinearLayout
                android:id="@+id/wallet"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:background="@color/wolletColor"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="@dimen/dimen_50dp"
                    android:layout_height="@dimen/dimen_50dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="@dimen/dimen_20dp"
                    android:background="@drawable/wallet" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_marginStart="@dimen/dimen_4dp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/wallet_remains"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="@dimen/dimen_10dp"
                        android:text="3450.00 LKR"
                        android:textColor="@color/colorPrimary"
                        android:textSize="@dimen/dimen_16dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/wallet_remains"
                        android:textColor="@color/gray"
                        android:textSize="@dimen/dimen_12dp" />
                </LinearLayout>

            </LinearLayout>

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

                <LinearLayout

                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:orientation="horizontal"
                    android:paddingTop="@dimen/dimen_60dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:orientation="vertical"
                        android:padding="@dimen/dimen_20dp">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginBottom="@dimen/dimen_10dp"
                            android:text="Mobile No"
                            android:textColor="@color/borderAndFont"
                            android:textSize="@dimen/dimen_20dp"></TextView>

                        <EditText
                            android:id="@+id/reload_mobile_number"
                            android:layout_width="match_parent"
                            android:layout_height="50dp"
                            android:layout_marginBottom="@dimen/dimen_20dp"
                            android:background="@drawable/rounded_edit_text"
                            android:gravity="center|center_vertical"
                            android:hint="@string/mobile_number"
                            android:inputType="phone"
                            android:textColor="@color/borderAndFont"
                            android:textSize="14sp" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginBottom="@dimen/dimen_10dp"
                            android:text="@string/amount"
                            android:textColor="@color/borderAndFont"
                            android:textSize="@dimen/dimen_20dp"></TextView>

                        <EditText
                            android:id="@+id/reload_amount"
                            android:layout_width="match_parent"
                            android:layout_height="50dp"
                            android:background="@drawable/rounded_edit_text"
                            android:gravity="center|center_vertical"
                            android:hint="@string/amount_hint"
                            android:inputType="number"
                            android:textColor="@color/borderAndFont"
                            android:textSize="14sp" />

                    </LinearLayout>


                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="@dimen/dimen_20dp"
                android:layout_marginStart="@dimen/dimen_20dp"
                android:gravity="bottom"
                android:orientation="vertical"
                app:layout_constraintBottom_toBottomOf="parent">

                <LinearLayout

                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/cancelBtn"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/dimen_10dp"
                        android:layout_marginEnd="@dimen/dimen_6dp"
                        android:layout_marginTop="@dimen/dimen_10dp"
                        android:layout_weight="1"
                        android:background="@drawable/secondary_button"
                        android:text="Cancel"
                        android:textColor="@color/white" />

                    <Button
                        android:id="@+id/btn_proceed"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/dimen_10dp"
                        android:layout_marginStart="@dimen/dimen_6dp"
                        android:layout_marginTop="@dimen/dimen_10dp"
                        android:layout_weight="1"
                        android:background="@drawable/primary_button"
                        android:text="Proceed"
                        android:textColor="@color/white" />
                </LinearLayout>
            </LinearLayout>
        </RelativeLayout>

AndroidManifest.xml

      <activity
                android:windowSoftInputMode="adjustResize"
                android:name=".ui.main.MainActivity"
                android:screenOrientation="sensorPortrait"
                android:theme="@style/AppTheme.NoActionBar"></activity>

Upvotes: 1

Views: 1843

Answers (2)

kulikovman
kulikovman

Reputation: 391

activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)

Upvotes: 0

Savin Sharma
Savin Sharma

Reputation: 799

Adding android:fitsSystemWindows="true and android:windowSoftInputMode="adjustResize" to the Main Activity won't work.

You have to add android:fitsSystemWindows="true to the parent layout of that particular Fragment xml file. And in the java class of the Fragment in your onCreateView you have to add windowSoftInputMode like this.

getActivity()
            .getWindow()
            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Hope this works for you. Let me know if you have any issue.

Upvotes: 2

Related Questions