Issue
AlertDialog only gets full screen after WebView inside of it is loaded:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
WebView wv = new WebView(this);
wv.loadUrl("https://google.com");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
FrameLayout container = new FrameLayout(MainActivity.this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
wv.setLayoutParams(params);
container.addView(wv);
builder.setView(container);
builder.setNegativeButton(getString(R.string.close), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(dialog.getWindow().getAttributes());
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(layoutParams);
dialog.show();
How do I make AlertDialog full height from the start?
EDIT: I think I found the answer; I needed to set height of WebView like this:
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, getResources().getDisplayMetrics().heightPixels * 0.8f, getResources().getDisplayMetrics());
params.height = height;
Solution
Try below code
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
or set your custom style in your style.xml
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
while inflating your dialog set this theme
alertDialog = new AlertDialog.Builder(this, R.style.DialogTheme);
Answered By - ismail alaoui


0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.