I am trying to load a pdf document from web to url (which I accessed in browser and its working well), when I load the url in WebView inside Custom AlertDialog
my WebView diaplays nothing.
alert_dialog_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingRight="10dp"
android:paddingEnd="10dp"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/web_view"
></WebView>
</RelativeLayout>
code:
private void showDoc(String fileName) {
final View view = getActivity().getLayoutInflater().inflate(R.layout.alert_dialog_webview, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setCancelable(false);
final WebView webview = (WebView) view.findViewById(R.id.web_view);
String url = BASE_URL+fileName;
//webview.loadUrl(url);
webview.setWebViewClient(new WebViewClient() {
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
webview.loadUrl(request.getUrl().toString());
return true;
}
});
String negativeText = getString(R.string.cancel);
builder.setNegativeButton(negativeText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
final AlertDialog dialog = builder.create();
dialog.setView(view);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(getContext(),R.color.colorAccentDark));
}
});
// display dialog
dialog.show();
}