create Bottom Dialog - Android User Interface

Android examples for User Interface:Dialog

Description

create Bottom Dialog

Demo Code


//package com.java2s;
import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

public class Main {

    public static AlertDialog createBottomDialog(Context context,
            int layout, int animation, boolean showSoftInput) {
        return createDialog(context, layout, animation, showSoftInput,
                Gravity.BOTTOM);/*ww  w  . j a  v a2 s  .  c  o  m*/
    }

    public static AlertDialog createDialog(Context context, int layout,
            int animation, boolean showSoftInput, int gravity) {
        AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.setContentView(layout);
        Window window = dialog.getWindow();
        if (showSoftInput) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = gravity;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        window.setWindowAnimations(animation);
        return dialog;
    }
}

Related Tutorials