我想在我的应用中使用progress bar with rounded circle
和loading....
文字。我搜索的更多。但仍然没有明确的想法。
默认栏:
预期栏:
注意:我只想在webview的xml文件中执行此操作。有人可以帮帮我吗
答案 0 :(得分:4)
您应该编写自定义webview client的代码,您可以在其中实现逻辑以在页面加载时显示自定义对话框并在页面结束时隐藏。
查看Android WebView and the Indeterminant Progress Solution
I want to do this only in xml file for webview. Could anybody please help me
这是什么意思?您想要更改进度条的UI吗?
如果是,请查看我的博客Customization of circular progress bar,它可以帮助您更改用户界面。
答案 1 :(得分:0)
制作自定义进度条,progressdialog ..
我认为这个link很有用..
答案 2 :(得分:-1)
请尝试以下代码:
布局:main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="@+id/llProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
</LinearLayout>
</FrameLayout>
代码:MainActivity.java
public class MainActivity extends Activity {
private LinearLayout llProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
llProgress = (LinearLayout) findViewById(R.id.llProgress);
showProgress("Loading...");
}
private void showProgress(String message) {
((TextView) llProgress.findViewById(R.id.tvMessage)).setText(message);
llProgress.setVisibility(View.VISIBLE);
}
private void hideProgress() {
((TextView) llProgress.findViewById(R.id.tvMessage)).setText("");
llProgress.setVisibility(View.GONE);
}
}
答案 3 :(得分:-2)
MyProgressDialog.class
: - 调用时将返回循环对话框的类。
import android.app.Dialog;
import android.content.Context;
import android.view.ViewGroup.LayoutParams;
import android.widget.ProgressBar;
public class MyProgressDialog extends Dialog {
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message) {
return show(context, title, message, false);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate,
boolean cancelable, OnCancelListener cancelListener) {
MyProgressDialog dialog = new MyProgressDialog(context);
dialog.setTitle(title);
dialog.setCancelable(cancelable);
dialog.setOnCancelListener(cancelListener);
/* The next line will add the ProgressBar to the dialog. */
dialog.addContentView(new ProgressBar(context), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
dialog.show();
return dialog;
}
public MyProgressDialog(Context context) {
super(context, R.style.NewDialog);
}
}
NewDialog的样式应该放在 String.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--=====This is the Style for the progressBar==================== -->
<style name="NewDialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
<!--============================================== -->
</resource>
ProgressDialog
?就是这样: - Dialog pd; // Declare it on the Top of the Activity using it to make it Global.
//Start of Dialog
pd=MyProgressDialog.show(ActivityName.this, "Loading", "");
// To Stop the Dialog
pd.dismiss();