How To Make Dialog Box Appear On The Left?
Solution 1:
If I understand your question correctly - you want to align your dialog not appear on the center of the screen. Then look at this code sample.
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
builder.setItems(items, newDialogInterface.OnClickListener() {
publicvoidonClick(DialogInterface dialog, int item) {
if(item == 0) {
} elseif(item == 1) {
} elseif(item == 2) {
}
}
});
AlertDialogdialog= builder.create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParamsWMLP= dialog.getWindow().getAttributes();
WMLP.x = 100; //x position
WMLP.y = 100; //y position
dialog.getWindow().setAttributes(WMLP);
dialog.show();
Here x position's value is pixels from left to right. For y position value is from bottom to top.
Solution 2:
Before calling #show() on your AlertDialog you can adjust the gravity of the dialog window:
AlertDialogdlg= ...;
dlg.getWindow().getAttributes().gravity = Gravity.LEFT|Gravity.CENTER_VERTICAL;
This would shift the dialog to the left of the screen. Adjust your gravity flags according to your taste.
Solution 3:
Just add following line in your java file and extra space will remove from dialog box.
Dialog dialog; dialog=new Dialog(Activity.this,android.R.style.Theme_DeviceDefault_Light_Panel);
Above code work for me. I hope it will be work for others too. Note: You need to pass activity context instead of normal context (getApplicationContext()).
Post a Comment for "How To Make Dialog Box Appear On The Left?"