【发布时间】:2017-03-06 05:42:27
【问题描述】:
我想要做的是将progressBar 消息的字体从默认更改为自定义。 我已经尝试了很多技术,但都失败了。
我尝试通过样式更改它,然后将此样式应用于我的对话框:
<style name="StyledDialog" parent="@android:style/Theme.Panel">
<item name="android:background">@android:color/transparent</item>
<item name="android:alertDialogStyle">@style/CustomStyle</item>
<item name="fontPath">fonts/Lato-Regular.ttf</item> // not working
</style>
<style name="CustomStyle">
<item name="fontPath">fonts/Lato-Regular.ttf</item> // not working
</style>
然后我尝试在 TextView 中获取消息,但我得到了 null
dialog = new ProgressDialog(getContext(), R.style.StyledDialog); //tried with styles here.
dialog.create(); //yep, create the dialog, see that dialogs's onCreate method was executed;
TextView view = (TextView) dialog.findViewById(R.id.message); // getting null
Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/epimodem.ttf");
view.setTypeface(face); //null pointerException
我正在使用 Calligraphy 库来更改我拥有的所有 textView 的字体。 那么你知道如何改变我对progressDialog的喜爱
【问题讨论】:
-
您是否尝试创建自定义对话框?
-
@Alexey move TextView view = (TextView) dialog.findViewById(R.id.message);显示对话框后。对话框.show();在此之后找到 textview 并且不会为空
-
你在使用 AlertDialog 吗??
-
请看一下这个答案:stackoverflow.com/a/16045641/1533933 并尝试首先使用 spans 更改进度对话框消息的颜色/大小(以确保字体或类似的东西没有问题)。成功后 - 从这里尝试 TypeFace span:stackoverflow.com/a/4826885/1533933 以使用自定义字体。希望对你有帮助
-
成功了,谢谢。考虑发布答案。
标签: android android-styles android-progressbar