Android 将进度条微调器添加到弹出对话框WebView
我已经尝试为下面的代码实现一个进度条微调器。我对android编程相当陌生,并尝试过搜索和尝试示例。下面的代码是我所拥有的,用于显示弹出窗口,并具有带有自定义关闭按钮的webview。有人能告诉我或指导我如何使用进度微调器和以下代码吗?多谢各位Android 将进度条微调器添加到弹出对话框WebView,android,webview,android-alertdialog,android-progressbar,Android,Webview,Android Alertdialog,Android Progressbar,我已经尝试为下面的代码实现一个进度条微调器。我对android编程相当陌生,并尝试过搜索和尝试示例。下面的代码是我所拥有的,用于显示弹出窗口,并具有带有自定义关闭按钮的webview。有人能告诉我或指导我如何使用进度微调器和以下代码吗?多谢各位 package com.example.expopup; import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.
package com.example.expopup;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity {
Dialog myDialog;
Button myButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button) findViewById(R.id.ClkBtn);
myButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
myDialog = new Dialog(MainActivity.this);
myDialog.setContentView(R.layout.mydialog);
myDialog.setTitle("Test");
myDialog.setCancelable(true);
WebView myWebView = (WebView) myDialog.findViewById(R.id.testwebview);
myWebView.loadUrl("http://google.com");
ImageButton close = (ImageButton)myDialog.findViewById(R.id.Btn1);
close.setOnClickListener(
new OnClickListener(){
public void onClick(View v) {
myDialog.dismiss();
}
});
myDialog.show();
}
});
}
}您可以这样使用
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setCancelable(true);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Test");
progressDialog.show();
我不确定您在WebView中使用的布局类型,但您可能希望在WebView最初隐藏的框架布局中同时包含WebView和ProgressBar。然后,您可以在页面完全加载后显示WebView并隐藏ProgressBar R.layout.mydialog
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView android:id="@+id/testwebview"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_height="match_parent" />
<ProgressBar android:id="@+id/testprogressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
谢谢你。这就是我需要的。我真的很感谢你的帮助。
myButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
myDialog = new Dialog(MainActivity.this);
myDialog.setContentView(R.layout.mydialog);
myDialog.setTitle("Test");
myDialog.setCancelable(true);
final WebView myWebView = (WebView) myDialog.findViewById(R.id.testwebview);
final ProgressBar myPB = (ProgressBar) myDialog.findViewById(R.id.testprogressbar);
// Add WebViewClient to be notified of page load
myWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
// Show webview and hide progress bar
myWebView.setVisibility(View.VISIBLE);
myPB.setVisibility(View.INVISIBLE);
}
});
myWebView.loadUrl("http://google.com");
ImageButton close = (ImageButton)myDialog.findViewById(R.id.Btn1);
close.setOnClickListener(
new OnClickListener(){
public void onClick(View v) {
myDialog.dismiss();
}
});
myDialog.show();
}
});