AlertDialog with custom view does not "resize",

I am having a problem with AlertDialog and user content / view. It is simply said that AlertDialog does not resize when the soft keyboard is opened. The following screenshots show what my problem is and what I want to achieve:

Current behavior (left) and desired behavior (right)

Current behaviorwanted behavior

I know there are several more threads with a similar problem on SO. Unfortunately, none of the solutions provided worked for me. Following my sample code:

XML

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

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

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </EditText>
    </LinearLayout>

</ScrollView>

Java - CustomAlertDialog.class

public class CustomAlertDialog extends AlertDialog{

    private Context context;

    public CustomAlertDialog(Context context) {
        super(context);
        this.context = context;
    }

    public void buildDialog(){
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.dialog_content, null);
        builder = new AlertDialog.Builder(context);
        builder.setTitle("EditText");
        builder.setView(layout);
        builder.setPositiveButton("Ok", new OnClickListener() {

            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                dismiss();
            }
        });
        builder.create();
    }

    public void showDialog(){
        builder.show();
    }
}

The above class / function is called by clicking a button in my Main.java class

btnAlertDialog.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            CustomAlertDialog dialog = new CustomAlertDialog(Main.this);
            dialog.buildDialog();
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            dialog.showDialog();
        }
    });

I have tried the following things:

Adding scrollbars to LinearLayout like this

android:scrollbars="vertical" 
android:scrollbarAlwaysDrawVerticalTrack="true"

Result: nothing has changed

Setting the flag for the dialog:

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

Result: nothing has changed

AlertDialog:

<style name="AlertDialog" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowFullscreen">false</item>
</style>

Java

builder = new AlertDialog.Builder(context, R.style.AlertDialog);

. , ,

Custom style - new problem

, . !

CustomAlertDialog.class. . nandeesh , .

public void startDialog(){
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.dialog_content, null);
        builder = new AlertDialog.Builder(context);
        builder.setTitle("EditText");
        builder.setView(layout);
        builder.setPositiveButton("Ok", new OnClickListener() {

            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                dismiss();
            }
        });
        AlertDialog aDialog = builder.create();
        aDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        aDialog.show();
    }
+5
2

, setSoftInputmode

builder.show();

AlertDialog mDialog = builder.create();
mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
mDialog.show();

, CustomAlertDialog

+6

, , , .., WindowSoftInputMode.

SoftInputMode AndroidManifest.xml Activity .

, ScrollView.

0

All Articles