我坚持了整整 2 天,这样做。 到目前为止,我只能使用样式 XML 文件更改标题文本颜色。除此之外,没有任何属性可以很好地工作。几乎涵盖了所有 STACK OVERFLOW 的问题,但运气不好,没能找到答案。
这是我想做的:
(删除按钮获得焦点)
截至目前,我只能通过获取 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/