问题
I have used progressDialog in my android application and i have used code as
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();
I want to change the message font size and want to add some color to the message is it possible?
回答1:
Change the ProgressDialog Message font size in android programmatically:
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:
Make custom progress dialog like below:
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();
}
}
and then use progress dialog class in asynctask like below:
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();
}
来源:https://stackoverflow.com/questions/28315413/how-to-change-the-progressdialog-message-font-size-in-android-programmatically