gpt4 book ai didi

android - 使用 android.support.v7.app.AlertDialog 自定义默认的 Theme.AppCompat.Dialog.Alert

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:18 24 4
gpt4 key购买 nike

我最近将应用中的 AlertDialog 实例切换为使用 android.support.v7.app.AlertDialog,但在应用自定义主题时遇到了问题,并且警报对话框的样式。

在我的 styles.xml 中,我有以下样式:

<style name="AlertDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorAccent">@color/theme_accent_1</item>
<item name="background">@color/theme_component_background</item>
<item name="android:background">@color/theme_component_background</item>
</style>

在我的 themes.xml 中,我根据需要在我的主题中设置了以下内容:

<item name="android:alertDialogTheme">@style/AlertDialog</item>

由于某些原因,自定义样式从未应用于 AlertDialog 实例,它们仍然是默认的 Theme.AppCompat.Dialog.Alert 主题。

如果我明确设置要使用的样式资源如下,它确实有效:

AlertDialog.Builder builder = 
new AlertDialog.Builder(getActivity(), R.style.AlertDialog);

有没有办法在整个主题中设置默认样式,而不必在 Builder 构造函数中指定主题?

最佳答案

根据 Pankaj Kumar 的回复,该链接详细说明了解决方案,即在名称属性中包含和不包含“android:”前缀的声明。

<item name="android:alertDialogTheme">@style/AlertDialog</item>
<item name="alertDialogTheme">@style/AlertDialog</item>

关于android - 使用 android.support.v7.app.AlertDialog 自定义默认的 Theme.AppCompat.Dialog.Alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30522082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com