变化在DialogFragment ProgressDialog的字体字样 [英] Change font typeface of ProgressDialog within DialogFragment
问题描述
我可以知道是否有可能改变 ProgressDialog
的消息显示的字体字样,在 DialogFragment
?
公共类LoadFromCloudTaskFragment扩展DialogFragment { @覆盖
公共对话框onCreateDialog(捆绑savedInstanceState){
this.progressDialog =新ProgressDialog(this.getActivity());
this.progressDialog.setMessage(progressMessage);
this.progressDialog.setCanceledOnTouchOutside(假); 返回progressDialog;
}
从 ProgressDialog
继承创建一个自定义类可能的途径之一。不过,我想知道有没有更好的选择吗?可悲的是,我们没有 ProgressDialog.Builder
。
一个我曾试图替代的是
@覆盖
公共对话框onCreateDialog(捆绑savedInstanceState){
this.progressDialog =新ProgressDialog(this.getActivity());
this.progressDialog.setMessage(progressMessage);
this.progressDialog.setCanceledOnTouchOutside(假); Utils.setCustomFont(this.progressDialog.findViewById(android.R.id.message),Utils.ROBOTO_LIGHT_FONT); 返回progressDialog;
}
但是,这会给我误差
android.util.AndroidRuntimeException:requestFeature()必须被调用
添加内容之前
块引用>解决方案一个建议的解决方案是如下。但我不认为这是一个好办法。任何进一步的建议都非常欢迎。
公共类ProgressDialogEx扩展ProgressDialog {
公共ProgressDialogEx(上下文的背景下){
超级(上下文);
} @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
查看查看= this.findViewById(android.R.id.message);
如果(查看!= NULL){
//不应为null。只是要偏执足够了。
Utils.setCustomFont(查看,Utils.ROBOTO_LIGHT_FONT);
}
}
}公共类LoadFromCloudTaskFragment扩展DialogFragment { @覆盖
公共对话框onCreateDialog(捆绑savedInstanceState){
this.progressDialog =新ProgressDialogEx(this.getActivity());
this.progressDialog.setMessage(progressMessage);
this.progressDialog.setCanceledOnTouchOutside(假); 返回progressDialog;
}May I know is it possible to change the font typeface of
ProgressDialog
's message display, withinDialogFragment
?public class LoadFromCloudTaskFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { this.progressDialog = new ProgressDialog(this.getActivity()); this.progressDialog.setMessage(progressMessage); this.progressDialog.setCanceledOnTouchOutside(false); return progressDialog; }
Create a custom class by inheriting from
ProgressDialog
might be one of the ways. However, I wish to know is there any better alternative? Sadly, we do not haveProgressDialog.Builder
.One of the alternative I had tried is
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { this.progressDialog = new ProgressDialog(this.getActivity()); this.progressDialog.setMessage(progressMessage); this.progressDialog.setCanceledOnTouchOutside(false); Utils.setCustomFont(this.progressDialog.findViewById(android.R.id.message), Utils.ROBOTO_LIGHT_FONT); return progressDialog; }
But this will give me error
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
解决方案One of the suggested solution is as follow. But I don't think this is a good way. Any further suggestion are very much welcomed.
public class ProgressDialogEx extends ProgressDialog { public ProgressDialogEx(Context context) { super(context); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = this.findViewById(android.R.id.message); if (view != null) { // Shouldn't be null. Just to be paranoid enough. Utils.setCustomFont(view, Utils.ROBOTO_LIGHT_FONT); } } }
public class LoadFromCloudTaskFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { this.progressDialog = new ProgressDialogEx(this.getActivity()); this.progressDialog.setMessage(progressMessage); this.progressDialog.setCanceledOnTouchOutside(false); return progressDialog; }
这篇关于变化在DialogFragment ProgressDialog的字体字样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!