Adjust Alertdialog with Open Keyboard

Asked

Viewed 306 times

4

I have the following problem I have a Alertdialog

inserir a descrição da imagem aqui

When the keyboard is opened, the dialog goes up, but part of the dialog is hidden.. it does not adjust the height as per keyboard

inserir a descrição da imagem aqui

XML dialog:

<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout 
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/root_view"
                  android:layout_marginTop="@dimen/activity_vertical_margin"
                  android:layout_marginBottom="@dimen/activity_vertical_margin"
                  android:layout_marginLeft="@dimen/activity_horizontal_margin"
                  android:layout_marginRight="@dimen/activity_horizontal_margin" >

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:id="@+id/txtCliente"
                android:text="Cliente : XXXXXXXXXXXXXXXXX" />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:id="@+id/txtData"
                android:layout_marginTop="3dp"
                android:text="Data : XX/YY/ZZZZ hh:MM:ss" />



        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:text="Motivo" />

            <Spinner
                    android:layout_marginLeft="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/spinner"/>
        </LinearLayout>

        <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:lines="3"
                android:maxLength="200"
                android:id="@+id/txtObs"
                android:layout_gravity="center_horizontal"/>


    </LinearLayout>

</ScrollView>

Code that generates Alertdialog

LayoutInflater inflater = LayoutInflater.from(mContext);
View dialog_layout = inflater.inflate(R.layout.dialog_motivonaoatendimento, null);

AlertDialog.Builder db = new AlertDialog.Builder(mContext);

db.setView(dialog_layout);
db.setTitle("Não Atendimento");
db.setPositiveButton("Confirmar", new
        DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });

db.setNegativeButton("Cancelar", null);

final AlertDialog alertDialog = db.create();
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

db.show();

An observation that I noticed, it seems that the scrollview does not work. In some tests I saw that the "first" layout it does not obey, and the scrollview forces you to put the layout as "father".

I don’t know if that could be the cause of the problem..

Thank you for your attention.

  • Can’t you put another layout one level above the scrollview? layout>scroll>layout>widgets

1 answer

4


If the EditText is inside your Dialog, will do just that. A possible solution is you define the InputType of your EditText. Then you will be able to use the event on your keyboard, in which by clicking on DONE, it (the keyboard) will disappear showing the complete dialog with the appropriate buttons. See:

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:lines="3"
android:maxLength="200"
android:id="@+id/txtObs"
android:layout_gravity="center_horizontal"
android:inputType="text"/>

Imagery

inserir a descrição da imagem aqui

Here are some examples here article on inputType.

Details

Browser other questions tagged

You are not signed in. Login or sign up in order to post.