1

I'm a newbie in Android app development. I know there are a lot of similar question, but I think this one is a bit different, and nothing I've tried is working. I have a login activity with an AppBar and some EditTexts. When the user select the first one, the keyboard appears and pushes everything up. The first EditText is pushed under the AppBar, and I can't scroll down the view, only upside.

In the manifest I have set android:windowSoftInputMode="stateHidden|adjustResize". This is the layout of my activity:

<?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:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    tools:context=".Login.MainLoginActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbarMainLogin"
            app:layout_scrollFlags="scroll"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:titleTextColor="@android:color/white">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="18dp"
                android:gravity="center"
                android:text="Backoffice"
                android:textColor="@android:color/white"
                android:textSize="20sp" />
        </androidx.appcompat.widget.Toolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appbar"
        android:layout_centerInParent="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:orientation="vertical"
            android:paddingLeft="24dp"
            android:paddingRight="24dp">

            <!--  Server Label -->
            <TextView
                android:id="@+id/loginLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:layout_marginBottom="16dp"
                android:gravity="center_horizontal"
                android:lines="1"
                android:text="@string/loginLabel"
                android:textAlignment="center"
                android:textColor="@android:color/white"
                android:textSize="22sp" />

            <!--  Port Label -->
            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:textColorHint="@color/colorPrimaryLight"
                android:theme="@style/TextInputLayoutTheme">

                <EditText
                    android:id="@+id/inputServer"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:hint="Server IP"
                    android:inputType="textNoSuggestions|textPersonName"
                    android:text="192.168.2.1"
                    android:textColor="@android:color/white" />
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:textColorHint="@color/colorPrimaryLight"
                android:theme="@style/TextInputLayoutTheme">

                <EditText
                    android:id="@+id/inputPort"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:hint="Port"
                    android:inputType="textNoSuggestions|number"
                    android:text="8080"
                    android:textColor="@android:color/white" />
            </com.google.android.material.textfield.TextInputLayout>

            <!--  Username Label -->
            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:textColorHint="@color/colorPrimaryLight"
                android:theme="@style/TextInputLayoutTheme">

                <EditText
                    android:id="@+id/inputUsername"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:hint="Username"
                    android:inputType="textNoSuggestions|textPersonName"
                    android:text="maser"
                    android:textColor="@android:color/white" />
            </com.google.android.material.textfield.TextInputLayout>

            <!--  Password Label -->
            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:textColorHint="@color/colorPrimaryLight"
                android:theme="@style/TextInputLayoutTheme">

                <EditText
                    android:id="@+id/inputPassword"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:hint="Password"
                    android:inputType="textPassword"
                    android:text="maser"
                    android:textColor="@android:color/white" />
            </com.google.android.material.textfield.TextInputLayout>

            <RadioGroup
                android:id="@+id/idSedeGroup"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/multimpiantoRadio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="@android:color/white"
                    android:checked="true"
                    android:text="Multimpianto"
                    android:textAlignment="viewStart"
                    android:textColor="@android:color/white"
                    android:textSize="17sp" />

                <RadioButton
                    android:id="@+id/standaloneRadio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="@android:color/white"
                    android:text="Standalone"
                    android:textAlignment="viewStart"
                    android:textColor="@android:color/white"
                    android:textSize="17sp" />

            </RadioGroup>

            <androidx.appcompat.widget.AppCompatButton
                android:id="@+id/loginButton"
                android:layout_width="fill_parent"
                android:layout_height="36dp"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
                android:background="@color/colorPrimary"
                android:onClick="loginPressed"
                android:text="Accedi"
                android:textColor="@android:color/white" />

            <CheckBox
                android:id="@+id/checkCredenziali"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:buttonTint="@android:color/white"
                android:checked="true"
                android:gravity="center"
                android:layoutDirection="rtl"
                android:text="Memorizza credenziali:   "
                android:textColor="@android:color/white"
                android:textSize="16sp" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

screenshot

I have also tried as suggested to wrap everything into a ScrollView and to change in the manifest the windowSoftInputMode to adjustPan, but nothing is scrolling.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
    android:scrollbars="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        tools:context=".Login.MainLoginActivity">
...
Silvia
  • 21
  • 2

2 Answers2

1

Try puting the value for windowSoftInputMode to "adjustPan" in your manifest file's activity tag

android:windowSoftInputMode="adjustPan"

and you need to wrap your content with ScrollView

you can have a look at this question too

Shankar
  • 2,890
  • 3
  • 25
  • 40
  • I've tried that, but then I can't scroll the view, and to get to the bottom text edit the user has to close the keyboard and click again the text field. – Silvia Nov 07 '19 at 08:14
  • wrap your activity design in the scroll bar, that is what I asked you to look into my question, it uses scroll bar :). Please, let me know if you still face issues :) – Shankar Nov 07 '19 at 14:24
  • I've put everything inside a ScrollView but it still don't scroll, I've updated my answer to show how I've done it. – Silvia Nov 15 '19 at 08:40
0

Try wrapping all in a Scrollview....that should work

also check this:: How to make my layout able to scroll down?

Wisdom
  • 40
  • 6
  • I've modified my answer to show how I've tried your suggestion, but I think I'm doing something wrong because I can't scroll the view. – Silvia Nov 15 '19 at 08:43