Java 我需要我的应用程序代码的进度条代码
有人能帮我添加进度条吗? 我已经在代码中添加了各种进度条方法,但在页面成功加载后,进度条不会结束 这是我的MainActivity.java:Java 我需要我的应用程序代码的进度条代码,java,android,webview,progress,Java,Android,Webview,Progress,有人能帮我添加进度条吗? 我已经在代码中添加了各种进度条方法,但在页面成功加载后,进度条不会结束 这是我的MainActivity.java: package com.myappname.app; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.Men
package com.myappname.app;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.pushbots.push.Pushbots;
public class MainActivity extends Activity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Pushbots.sharedInstance().init(this);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Use remote resource
mWebView.loadUrl("http://www.mysiteurl.com");
// Stop local links and redirects from opening in browser instead of WebView
mWebView.setWebViewClient(new MyAppWebViewClient());
// Use local resource
// mWebView.loadUrl("file:///android_asset/www/index.html");
}
// Prevent the back-button from closing the app
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Alert")
.setMessage("Are you sure you want exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", null)
.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是我在布局中的activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/activity_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
建议在AsyncTask中使用进度对话框。 因此,首先声明一个进度对话框:
ProgressDialog progressDialog;
初始化它:
this.progressDialog = new ProgressDialog(context);
然后在内部执行:
progressDialog.setMessage("Loading");
progressDialog.show();
和内部PostExecute:
progressDialog.dismiss();
由于这是我的第一个应用程序,所以我对它没有太多的了解,你能在我上面的代码中实现进度条形码吗?你必须先实现AsyncTask。请尝试以下示例,您可以查看以下内容: