WebView внутри AlertDialog не полная высота до загрузки страницы - PullRequest
0 голосов
/ 15 мая 2019

AlertDialog открывается на весь экран только после загрузки WebView внутри него:

enter image description here

enter image description here

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();

Как мне сделать AlertDialog на полную высоту с самого начала?


EDIT : мне кажется, я нашел ответ;Мне нужно было установить высоту WebView следующим образом:

int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, getResources().getDisplayMetrics().heightPixels * 0.8f, getResources().getDisplayMetrics());
params.height = height;

1 Ответ

1 голос
/ 15 мая 2019

Попробуйте код ниже

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);

или задайте свой собственный стиль в вашем 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>

при накачивании диалогового окнаустановить эту тему

alertDialog  = new AlertDialog.Builder(this, R.style.DialogTheme);
...