android - 如何在 android 中为 Alertdialog.builder 的分隔线着色?

标签 android

我正在使用 AlertDialog.Builder 类通过单选按钮和取消按钮构建警报,我想更改分隔线的颜色和单选按钮的颜色如何做到这一点,请提供解决方案。我检查了 stackoverflow 中关于此相关问题的所有答案。 还有一个我正在使用 v7Appcomapact 库。我的最小 sdk 是 10,最大是 18。我不想使用自定义布局。

最佳答案

试试这个

public static void brandAlertDialog(AlertDialog dialog) {
try {
    Resources resources = dialog.getContext().getResources();
    int color = resources.getColor(...); // your color here

    int alertTitleId = resources.getIdentifier("alertTitle", "id", "android");
    TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
    alertTitle.setTextColor(color); // change title text color

    int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
    View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
    titleDivider.setBackgroundColor(color); // change divider color
} catch (Exception ex) {
    ex.printStackTrace();
}}

已回答here

关于android - 如何在 android 中为 Alertdialog.builder 的分隔线着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27577278/

相关文章:

java - 如何通过完整性检查从 Dropbox 下载文件?

java - 在 Android 的 GridView 中放置图像(从 URL 加载)和编辑文本框

Android Firebase 多图上传

Java 将 <Preference> 从一个 PreferenceScreen 移动到另一个?

java - RSA 加密编码使用 Android 解密使用 apache 编解码器问题

android - 将两个 ConstraintLayout 带到 Button 前面

Android ffmpeg 保存并 append h264 流视频

android - 项目更新推荐 : Android Gradle Plugin can be upgraded. 错误信息:在构建文件中找不到 AGP 版本

android - 如何通过命令行在 Linux 中更新 Android SDK

android - 打开一个 12kb 的文本文件需要太长时间......?