Skip to content

Instantly share code, notes, and snippets.

@douzifly
Created June 30, 2014 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douzifly/148975a2feed13904b2f to your computer and use it in GitHub Desktop.
Save douzifly/148975a2feed13904b2f to your computer and use it in GitHub Desktop.
dialog width match parent
void show() {
final Dialog dialog = new Dialog(this);
final Window window = dialog.getWindow();
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
// set content view must before set other attributes
dialog.setContentView(R.layout.dialog_content);
final WindowManager.LayoutParams lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.dimAmount = 0.3f;
lp.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
lp.softInputMode |= WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
lp.gravity = Gravity.BOTTOM;
window.setAttributes(lp);
dialog.getWindow().setBackgroundDrawable(null);
dialog.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment