【问题标题】:How to change the ProgressDialog Message font size in android programmatically?如何以编程方式更改android中的ProgressDialog Message字体大小?
【发布时间】:2015-02-04 07:05:54
【问题描述】:

我在我的 android 应用程序中使用了 progressDialog,并且我使用了代码作为

ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMessage("Please wait to get contacts");
        progressDialog.setProgress(0);

        progressDialog.show();

我想更改消息字体大小并想给消息添加一些颜色可以吗?

【问题讨论】:

标签: android text progressdialog


【解决方案1】:

以编程方式更改 android 中的 ProgressDialog Message 字体大小:

String s= "Hello";
String title="MyTitle";

SpannableString ss1=  new SpannableString(title);
ss1.setSpan(new RelativeSizeSpan(2f), 0, ss1.length(), 0);  
ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, ss1.length(), 0); 
SpannableString ss2=  new SpannableString(s);
ss2.setSpan(new RelativeSizeSpan(2f), 0, ss2.length(), 0);  
ss2.setSpan(new ForegroundColorSpan(Color.GREEN), 0, ss2.length(), 0); 

ProgressDialog pd = new ProgressDialog(this);
pd.setTitle(ss1);
pd.setMessage(ss2);
pd.show();

【讨论】:

    【解决方案2】:
    private ProgressDialog Dialog = new ProgressDialog(currentfile.this);
    
    Dialog.setMessage(Html.fromHtml("<font color='white'  ><big>"
                        + "Downloading ..." + "</big></font>"));
    
    Dialog.show();
    

    【讨论】:

      【解决方案3】:

      制作如下自定义进度对话框:

      custom_progress_dialog.xml

      <LinearLayout
        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"
        android:gravity="center"
        android:background="@null"
      >
        <TextView
          android:id="@+id/animation"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/string"
          android:size="30dp"  />
      </LinearLayout>
      

      MyCustomProgressDialog.java

      public class MyCustomProgressDialog extends ProgressDialog {
          @Override
          protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.custom_progress_dialog);
      
            ...
          }
          public static MyCustomProgressDialog ctor(Context context) {
              MyCustomProgressDialog dialog = new MyCustomProgressDialog(context);
              dialog.setIndeterminate(true);
              dialog.setCancelable(false);
              return dialog;
          }
      
      
           @Override
           public void show() {
              super.show();
          }
      
          @Override
          public void dismiss() {
            super.dismiss();
           }
      
      
      }
      

      然后在 asynctask 中使用进度对话框类,如下所示:

      class DemoAsyncTask extends AsyncTask<Void, Void, Void> {
        private final MyCustomProgressDialog progressDialog;
      
        public DemoAsyncTask(Context ctx) {
          progressDialog = MyCustomProgressDialog.ctor(ctx);
        }
      
        @Override
        protected void onPreExecute() {
          super.onPreExecute();
          textView.setVisibility(View.INVISIBLE);
      
          progressDialog.show();
        }
      

      【讨论】:

        猜你喜欢
        • 2013-01-09
        • 2012-09-24
        • 2015-08-10
        • 1970-01-01
        • 1970-01-01
        • 2016-07-20
        • 1970-01-01
        • 2015-01-22
        相关资源
        最近更新 更多