我有一个弹出窗口,用于在我的应用程序中下载音频说明。我想做的是将默认文本颜色“OK”更改为蓝色。我尝试了一些东西,但是没有用。这是我的代码:
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();
}
但是这种变化并不能反射(reflect)出有人能告诉我我做错了什么吗?
最佳答案
您必须在AlertDialog构造函数中提供一个自定义样式ID:
AlertDialog.Builder(Context context, int themeResId)
样式文件应类似于:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorAccent">#0000FF</item>
</style>
关于android - 更改警报对话框的文本颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38609262/