У меня есть веб-представление, которое находится внутри диалога аутентификации и содержит макет auth_dialog. xml. Я не могу понять, почему содержимое webview не совсем подходит внутри моего диалога после указания атрибутов, соответствующих родительскому.
Это скриншот проблемы, с которой я сталкиваюсь Изображение webview внутри диалога
Это код вызова диалога
AuthenticationDialog authenticationDialog = new AuthenticationDialog(this, this);
authenticationDialog.setCancelable(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(authenticationDialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
authenticationDialog.show();
authenticationDialog.getWindow().setAttributes(lp);
Это код внутри диалога
public class AuthenticationDialog extends Dialog {
private static final String TAG = "AuthenticationDialog";
WebView webView;
//urls
private final String request_url;
private final String redirect_url;
//Constructor Arguments
private AuthenticationListener listener;
private Context context;
public AuthenticationDialog(@NonNull Context context, AuthenticationListener listener) {
super(context);
this.context = context;
this.listener = listener;
this.redirect_url = Constants.REDIRECTURI;
this.request_url = Constants.BASEURL +
"oauth/authorize/?client_id=" +
Constants.CLIENTID +
"&redirect_uri=" + redirect_url +
"&response_type=code&scope=user_profile,user_media";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.auth_dialog);
//working with webview to get authcode
initializeWebView();
}
@SuppressLint("SetJavaScriptEnabled")
private void initializeWebView() {
Log.d(TAG, request_url);
webView = findViewById(R.id.instaWebView);
webView.requestFocus();
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setGeolocationEnabled(true);
webView.setSoundEffectsEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
webView.setWebViewClient(webViewClient);
webView.setMinimumHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
webView.setMinimumWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
webView.loadUrl(request_url);
}
WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d(TAG, "shouldOverrideUrlLoading: " + url);
if (url.startsWith(redirect_url)) {
AuthenticationDialog.this.dismiss();
return true;
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d(TAG, url);
if (url.contains("code=")) {
String access_token = url.substring(url.lastIndexOf("=") + 1, url.lastIndexOf("#"));
Log.d(TAG, "onPageFinished: " + access_token);
listener.onTokenReceived(access_token);
dismiss();
} else if (url.contains("?error")) {
Log.e("access_token", "getting error fetching access token");
dismiss();
}
}
};
}
Это authDialog. xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<WebView
android:id="@+id/instaWebView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</RelativeLayout>