更改警报对话框的文本颜色 [英] Change text color of alert dialog
本文介绍了更改警报对话框的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个弹出窗口,用于在我的应用程序中下载音频说明.我想做的是将默认文本颜色"OK"更改为蓝色.我尝试了一些东西,但是没有用.这是我的代码:
I have a popup for downloading the audio instruction in my app. What I am trying to do is I want to change the default text color of "OK" to blue. I tried something but its not working. Here is my code:
private void showDownloadPgmPopup() {
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
builder.setTitle("Download instructional audio?");
builder.setMessage(ParamConstants.AUDIODOWNLOADPERMISSION);
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
WwDatabaseHelper.storeSelectedWeekAndDay(getActivity(), mSelectedWeekDataModel);
goToMoveScreen();
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AndroidDownloadFileByProgressBarActivity.StartAudioAssetDownload(getActivity());
}
}).create();
// change the text color of download instruction ok button
final android.app.AlertDialog dialog = builder.show();
dialog.setOnShowListener( new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#ff5722"));
}
});
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
但是这种变化并不能反映出有人能告诉我我做错了吗?
But the change is not reflecting can anyone tell me what i am doing wrong?
推荐答案
您必须在AlertDialog构造函数中提供自定义样式ID:
You have to provide a custom style id in the AlertDialog constructor:
AlertDialog.Builder(Context context, int themeResId)
和样式文件应类似于:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorAccent">#0000FF</item>
</style>
这篇关于更改警报对话框的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文