0

我想在我的应用程序中使用progress bar with rounded circleand 和loading....文本。我已经搜索了更多。但仍然没有得到明确的想法。

默认栏:

在此处输入图像描述

预期酒吧:

在此处输入图像描述

注意:我只想在 webview 的 xml 文件中执行此操作。有人可以帮我吗

4

3 回答 3

4

您应该编写自定义webview 客户端,您可以在其中实现逻辑以在页面加载时显示自定义对话框并在页面完成时隐藏。

看看Android WebView 和 Indeterminant Progress 解决方案

I want to do this only in xml file for webview. Could anybody please help me

这是什么意思?是否要更改进度条的 UI?

如果是,请查看我的博客自定义圆形进度条,它可以帮助您更改 UI。

于 2012-08-28T06:01:37.917 回答
-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);
}

}
于 2012-08-28T05:59:03.257 回答
-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 的Style 应该放在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();
于 2012-08-28T05:56:30.700 回答