gpt4 book ai didi

android - 在 webview 中添加进度对话框

转载 作者:技术小花猫 更新时间:2023-10-29 12:45:19 27 4
gpt4 key购买 nike

当页面在 webview 中加载时,我一直在尝试将进度对话框合并到我的应用程序中,因此不仅仅是空白屏幕。我知道这个问题随处可见,但我似乎无法找出对我有用的任何东西。我是编程和使用 android 的新手,所以任何信息都会有所帮助。以下是我目前拥有的代码。使用 onPageStarted 我收到 Bitmap 的编译错误,我不确定问题出在哪里。谢谢。

public class Grades extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);


//requesting system settings

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature( Window.FEATURE_PROGRESS);
WebView webview = new WebView(this);

//web settings

WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDisplayZoomControls(true);
webSettings.setBuiltInZoomControls(true);


setContentView(webview);

//loads webpages in webview instead of launching browser

webview.setWebViewClient(new WebViewClient() {
ProgressDialog prDialog;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
prDialog = ProgressDialog.show(Grades.this, null, "loading, please wait...");
super.onPageStarted(view, url, favicon);
}

@Override
public void onPageFinished(WebView view, String url) {
prDialog.dismiss();
super.onPageFinished(view, url);
}
});

//loading webpage
webview.loadUrl("page__link");
}

最佳答案

检查这段代码,

    final ProgressDialog pd = ProgressDialog.show(OnlinePaymentActivity.this, "", "Please wait, your transaction is being processed...", true);

WebView mWebview = (WebView)findViewById(R.id.webView1);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
mWebview.getSettings().setLoadWithOverviewMode(true);
mWebview.getSettings().setUseWideViewPort(true);
mWebview.getSettings().setBuiltInZoomControls(true);

mWebview.setWebViewClient(new WebViewClient() {

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
pd.show();
}

@Override
public void onPageFinished(WebView view, String url) {
pd.dismiss();
String webUrl = mWebview.getUrl();
}

});

mWebview .loadUrl("www.google.com");

关于android - 在 webview 中添加进度对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16849347/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com