public static void brandAlertDialog(AlertDialog dialog) { try { Resources resources = dialog.getContext().getResources(); int color = resources.getColor(R.color.weak_green); //你想要的颜色 int alertTitleId = resources.getIdentifier("alertTitle", "id", "android"); TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId); alertTitle.setTextColor(color); // 字体颜色 int titleDividerId = resources.getIdentifier("titleDivider", "id", "android"); View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId); titleDivider.setBackgroundColor(color); // 间隔线颜色 } catch (Exception ex) { ex.printStackTrace(); } }
传入你需要改变的dialog即可。