如何以编程方式更改 android 中的 ProgressDialog 消息字体大小?
How to change the ProgressDialog Message font size in android programmatically?
我在我的 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();
我想更改消息的字体大小并想给消息添加一些颜色,可以吗?
制作自定义进度对话框,如下所示:
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();
}
}
然后在异步任务中使用进度对话框 class,如下所示:
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();
}
以编程方式更改 android 中的 ProgressDialog 消息字体大小:
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();
private ProgressDialog Dialog = new ProgressDialog(currentfile.this);
Dialog.setMessage(Html.fromHtml("<font color='white' ><big>"
+ "Downloading ..." + "</big></font>"));
Dialog.show();
我在我的 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();
我想更改消息的字体大小并想给消息添加一些颜色,可以吗?
制作自定义进度对话框,如下所示:
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();
}
}
然后在异步任务中使用进度对话框 class,如下所示:
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();
}
以编程方式更改 android 中的 ProgressDialog 消息字体大小:
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();
private ProgressDialog Dialog = new ProgressDialog(currentfile.this);
Dialog.setMessage(Html.fromHtml("<font color='white' ><big>"
+ "Downloading ..." + "</big></font>"));
Dialog.show();