Reputation: 3
I want to the AlertDialog show in the bottom of screen, but hava a space between AlertDialog's bottom and screen's bottom.
My code is like below :
private void editor(Context context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
View view = addLayout(R.layout.edit_layout);
final AlertDialog myDialog = builder.create();
Window window = myDialog.getWindow();
myDialog.setView(view);
myDialog.show();
window.setGravity(Gravity.BOTTOM);// set the AlertDialog in screen the bottom.
}
So how the AlertDialog can be shown at the bottom of screen without the space?
Upvotes: 0
Views: 860
Reputation: 12304
private void editor(Context context, int theme, int customLayout) {
Dialog builder = new Dialog(context, theme);//R.style.customDialog
builder.setContentView(customLayout);
builder.show()
}
in file
res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="customDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowIsFloating">false</item>
</style>
</resources>
in your layout set main layout gravity to:
android:gravity="bottom|center_horizontal"
For making spacing of this customDialog style, put i.e android:padding
to 10dp
ps. didn't test but it should be working, ping me in any problem
Upvotes: 0
Reputation: 679
use this code hope it will helps.
AlertDialog dialog = builder.create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.Bottom | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
dialog.show();
Upvotes: 1