在 ProgressDialog 中更改文本对齐方式

发布于 2024-10-14 13:42:02 字数 750 浏览 2 评论 0原文

我有一个问题,如何更改进度对话框中的文本(基本上具有如图所示的 STYLE_HORIZONTAL)(使用 Android 1.6)

在此处输入图像描述

到如图所示的文本。

在此处输入图像描述

在这种情况下请提供帮助。 我关于进度对话框的代码是这样的:-

 mProgressDialog = new ProgressDialog(PDFActivity.this);

  mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

  mProgressDialog.setTitle(R.string.msgDownloadingWait);
  mProgressDialog.setMessage(getResources().getString(
    R.string.msgDownloading));

  // User is not allowed to cancel the download operation.
  mProgressDialog.setCancelable(false);

  mProgressDialog.setMax(serverFileCount);

  mProgressDialog.show(); 

提前致谢。

I have problem that how to change text inside the progressdialog (basically having STYLE_HORIZONTAL as in figure) (Using Android 1.6)

enter image description here

to text shown in figure.

enter image description here

Please help out in this case.
My code about the progressdialog refers like this:-

 mProgressDialog = new ProgressDialog(PDFActivity.this);

  mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

  mProgressDialog.setTitle(R.string.msgDownloadingWait);
  mProgressDialog.setMessage(getResources().getString(
    R.string.msgDownloading));

  // User is not allowed to cancel the download operation.
  mProgressDialog.setCancelable(false);

  mProgressDialog.setMax(serverFileCount);

  mProgressDialog.show(); 

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

邮友 2024-10-21 13:42:02

几天前我得到了与此内容相关的答案(但今天更新它,因为有一些空闲时间)。

这是我用来使这个东西最好的代码。我通过自定义对话框实现了上述目标。首先,这里是我调用自定义对话框类的活动代码。

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProgressThread extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MyDialog dialog = new MyDialog(this);
        dialog.show();
    }
}

现在是与自定义对话框相关的代码。在这里我使用了 ProgressBar & CustomDialog 中的 TextViews根据下载进行计算,进而更新 TextViews。此处使用的示例更新 textviews 和以虚拟方式显示进度条。您可以根据需要更改它。

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MyDialog extends Dialog {
    public static final int STATUS_UPDATE = 101;
    public static final int STATUS_COMPLETE = 100;
    ProgressBar progressBar;
    TextView textView;
    TextView percent;
    int increment;
    int progress;

    public MyDialog(Context context) {
        super(context);
        setContentView(R.layout.progressbar);

        setDialog();
    }

    private void setDialog() {
        setTitle("Downloading Files....");
        textView = (TextView) findViewById(R.id.textProgress);
        progressBar = (ProgressBar) findViewById(R.id.progress_horizontal);
        percent = (TextView) findViewById(R.id.textPercentage);

        percent.setTextColor(Color.WHITE);
        textView.setTextColor(Color.WHITE);

        progressBar.setProgressDrawable(getContext().getResources()
                .getDrawable(R.drawable.my_progress));
        progressBar.setIndeterminate(false);

        // set the maximum value
        progressBar.setMax(1315);

        launcherThread();

    }

    private void launcherThread() {

        LoaderThread loaderThread = new LoaderThread();
        loaderThread.start();

        LauncherThread launcherThread = new LauncherThread();
        launcherThread.start();

    }

    private class LoaderThread extends Thread {
        @Override
        public void run() {
            try {
                while (progressBar.getProgress() < progressBar.getMax()) {
                    // wait 500ms between each update
                    Thread.sleep(100);
                    increment++;
                    // active the update handler
                    progressHandler.sendEmptyMessage(STATUS_UPDATE);
                }
                progressHandler.sendEmptyMessage(STATUS_COMPLETE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    // handler for the background updating
    Handler progressHandler = new Handler() {
        public void handleMessage(Message msg) {

            switch (msg.what) {

            case STATUS_UPDATE:
                progressBar.setProgress(increment);
                float value = increment / 1315F;
                percent.setText(" " + ((int) (value * 100)) + "%");
                System.out.println(value * 100);
                textView.setText(String.valueOf(progressBar.getProgress())
                        .concat(" / " + progressBar.getMax()));
                break;

            case STATUS_COMPLETE:
                dismiss();
            }
        }
    };

    private class LauncherThread extends Thread {
        @Override
        public void run() {
            progressHandler.sendMessage(progressHandler.obtainMessage());
            progressHandler.sendEmptyMessage(0);
        }
    }
} 

I got the answer related to this stuff some days back(but updating it today as got some free time).

Here the code that I have used for making this stuff best.I achieved above thing by Custom Dialog.Firstly here the code of activity from which I called the class of Custom Dialog.

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProgressThread extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MyDialog dialog = new MyDialog(this);
        dialog.show();
    }
}

Now the code related to the Custom Dialog. Here I have used ProgressBar & TextViews in CustomDialog & made calculations on basis on download which in turn updates TextViews.The example used here updates the textviews & progressbar in dummy manner.You change that as per your need.

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MyDialog extends Dialog {
    public static final int STATUS_UPDATE = 101;
    public static final int STATUS_COMPLETE = 100;
    ProgressBar progressBar;
    TextView textView;
    TextView percent;
    int increment;
    int progress;

    public MyDialog(Context context) {
        super(context);
        setContentView(R.layout.progressbar);

        setDialog();
    }

    private void setDialog() {
        setTitle("Downloading Files....");
        textView = (TextView) findViewById(R.id.textProgress);
        progressBar = (ProgressBar) findViewById(R.id.progress_horizontal);
        percent = (TextView) findViewById(R.id.textPercentage);

        percent.setTextColor(Color.WHITE);
        textView.setTextColor(Color.WHITE);

        progressBar.setProgressDrawable(getContext().getResources()
                .getDrawable(R.drawable.my_progress));
        progressBar.setIndeterminate(false);

        // set the maximum value
        progressBar.setMax(1315);

        launcherThread();

    }

    private void launcherThread() {

        LoaderThread loaderThread = new LoaderThread();
        loaderThread.start();

        LauncherThread launcherThread = new LauncherThread();
        launcherThread.start();

    }

    private class LoaderThread extends Thread {
        @Override
        public void run() {
            try {
                while (progressBar.getProgress() < progressBar.getMax()) {
                    // wait 500ms between each update
                    Thread.sleep(100);
                    increment++;
                    // active the update handler
                    progressHandler.sendEmptyMessage(STATUS_UPDATE);
                }
                progressHandler.sendEmptyMessage(STATUS_COMPLETE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    // handler for the background updating
    Handler progressHandler = new Handler() {
        public void handleMessage(Message msg) {

            switch (msg.what) {

            case STATUS_UPDATE:
                progressBar.setProgress(increment);
                float value = increment / 1315F;
                percent.setText(" " + ((int) (value * 100)) + "%");
                System.out.println(value * 100);
                textView.setText(String.valueOf(progressBar.getProgress())
                        .concat(" / " + progressBar.getMax()));
                break;

            case STATUS_COMPLETE:
                dismiss();
            }
        }
    };

    private class LauncherThread extends Thread {
        @Override
        public void run() {
            progressHandler.sendMessage(progressHandler.obtainMessage());
            progressHandler.sendEmptyMessage(0);
        }
    }
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文