Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Created October 28, 2014 14:32
Show Gist options
  • Save ishitcno1/89ff4f671a952f3b0ccd to your computer and use it in GitHub Desktop.
Save ishitcno1/89ff4f671a952f3b0ccd to your computer and use it in GitHub Desktop.
android widget utils
public class WidgetUtils {
/**
* create alert dialog
*
* @param context
* @param layout
* @param showSoftInput
* @return
*/
public static AlertDialog createAlertDialog(Context context, int layout, boolean showSoftInput) {
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 lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
window.setAttributes(lp);
return dialog;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment