gpt4 book ai didi

java - 如何在 Activity 上设置进度条

转载 作者:行者123 更新时间:2023-11-30 04:11:24 25 4
gpt4 key购买 nike

这是我的代码...

public class detailedview extends Activity
{
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.detailedview);
GetSet gs = new GetSet();

String title = gs.getTitle();
String desc = gs.getDesc();

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setTextSize(TextSize.SMALLER);
mWebView.loadDataWithBaseURL("", "<p align=\"justify\"><b> " + title+"</p></b><p align=\"justify\"><br>"+ desc + "</p></br>", "text/html", "utf-8", "");

我想在 Activity 上设置一个 ProgressBar。我怎样才能做到这一点?帮助我。

最佳答案

下面的代码用于显示进度条:

ProgressDialog progressDialog = ProgressDialog.show(this, "Please Wait!", "Loading...");

并禁用它:

if (progressDialog != null) {
progressDialog.dismiss();
}

更新:

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
Window.PROGRESS_VISIBILITY_ON);
final WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/www/index.html");
final Activity MyActivity = this;
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Make the bar disappear after URL is loaded, and changes
// string to Loading...
MyActivity.setTitle("Loading...");
MyActivity.setProgress(progress * 100); // Make the bar
// disappear after URL
// is loaded

// Return the app name after finish loading
if (progress == 100)
MyActivity.setTitle(R.string.app_name);
}
});

关于java - 如何在 Activity 上设置进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816007/

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