在我的应用程序中,我加载了一个用户输入用户名/密码的WebView,如果用户不小心点击webview外,我不希望webview关闭,因为该页面必须再次进行网络调用才能加载此webview
我知道这可以用于Dialog(如此:dialog.setCanceledOnTouchOutside(true);
),但找不到类似的webview机制。
谢谢!
以下是代码:
@SuppressLint("SetJavaScriptEnabled")
public class LoginDialogFragment extends DialogFragment {
private static final String TAG = LoginDialogFragment.class.getSimpleName();
View mainView = null;
WebView webView = null;
OnLoginSucceeded loginSucceeded = null;
ProgressBar progressBar = null;
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mainView = inflater.inflate(R.layout.webview, container, false);
if (getDialog() != null)
getDialog().setTitle(getString(R.string.login));
webView = (WebView) mainView.findViewById(R.id.webview);
//display the progress bar
progressBar = (ProgressBar) mainView.findViewById(R.id.user_profile_loading_progress);
progressBar.setVisibility(View.VISIBLE);
//turn caching off
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
});
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.i(TAG, "URL received in onCreateView's onPageStarted is: " + url);
new HandleRequest().execute(url);
}
@Override
public void onPageFinished(WebView view, String url) {
}
});
new FetchLoginFormTask().execute();
return mainView;
}
答案 0 :(得分:1)
I found my answer here我刚刚使用getDialog().setCanceledOnTouchOutside(false);
确保在点击后退键时,网页视图将被解除。
答案 1 :(得分:0)
尝试覆盖方法:
@Override
public void setCancelable(boolean cancelable) {
super.setCancelable(false);
}
如果您的问题没有得到解决,请提供一些代码以便我帮助您。
随意发表评论。