android - 如何从我的主题 xml 文件自定义警报对话框按钮背景和标题分隔符

标签 android customization android-alertdialog android-theme

我坚持了整整 2 天,这样做。 到目前为止,我只能使用样式 XML 文件更改标题文本颜色。除此之外,没有任何属性可以很好地工作。几乎涵盖了所有 STACK OVERFLOW 的问题,但运气不好,没能找到答案。

这是我想做的:

enter image description here

(删除按钮获得焦点)

截至目前,我只能通过获取 titleDivider、Positive 和 Negative 按钮以及分配背景以编程方式执行此操作。但这就是说我讨厌以编程方式执行此操作。

有人请帮助我。

最佳答案

你可以使用这个项目AlertDialogPro . 将此项目包含在您的项目中并定义您的主题,如下所示:

<style name="YourAppTheme.AlertDialogProTheme" parent="AlertDialogProTheme.Holo.Light">
    <!-- Custom the title style -->
    <item name="android:windowTitleStyle">@style/YourDialogWindowTitle</item>
    <!-- Change the title divider to green -->
    <item name="adpTitleDividerBackground">@color/your_green_color</item>
    <!-- Change the button style -->
    <item name="adpButtonBarButtonStyle">@style/YourButtonStyle</item>
</style>

<style name="YourDialogWindowTitle" parent="DialogWindowTitle.Holo.Light">
    <item name="android:textColor">@color/your_green_color</item>
</style>

<style name="YourButtonStyle" parent="Widget.Holo.Button.Light">
    <item name="android:background">@drawable/your_button_background_selector</item>
    <item name="android:textColor">@color/your_button_text_selector</item>
</style>

并使用属性“alertDialogProTheme”将此主题指定为您应用的主题:

<style name="AppTheme" parent="AppBaseTheme">
  ...
  <item name="alertDialogProTheme">@style/YourAppTheme.AlertDialogProTheme</item>
</style>

使用 AlertDialogPro.Builder 构建对话框:

AlertDialogPro.Builder builder = new AlertDialogPro.Builder(getContext());
builder.setTitle("Delete").
    setMessage("Are you sure?").
    setPositiveButton("Delete", null).
    setNegativeButton("Cancel", null).
    show();

关于android - 如何从我的主题 xml 文件自定义警报对话框按钮背景和标题分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25915654/

相关文章:

android - Android 中的 AFSK 解调

c++ - gdb 输入/输出错误远程调试到 Android

vim - 诊断 Vim 中的键绑定(bind)问题

android - 自定义警报对话框滚动问题

android - 数据库行 ID 错误

android - 如何启用 google maps android api 以实现平滑的两指缩放?

android - 调用 alertDialog onStop/onPause

android - 为什么打开对话框时我的 "pressed"和/或 "selected"按钮状态丢失?

button - Froala 添加自定义预编码按钮

python - 使用自定义异常或使用ValueError哪个更好?