act*_*gic 4 android android-appcompat android-alertdialog
我最近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>
Run Code Online (Sandbox Code Playgroud)
在我的themes.xml中,我在主题中根据需要设置了以下内容:
<item name="android:alertDialogTheme">@style/AlertDialog</item>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,自定义样式永远不会应用于AlertDialog实例,它们仍然是默认Theme.AppCompat.Dialog.Alert主题.
如果我显式设置样式资源使用如下,它确实有效:
AlertDialog.Builder builder =
new AlertDialog.Builder(getActivity(), R.style.AlertDialog);
Run Code Online (Sandbox Code Playgroud)
有没有办法在整个主题中设置默认样式,而不必在Builder构造函数中指定主题?
根据Pankaj Kumar的回复,链接详细说明了解决方案,即在name属性中包含和不包含"android:"前缀的声明.
<item name="android:alertDialogTheme">@style/AlertDialog</item>
<item name="alertDialogTheme">@style/AlertDialog</item>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4076 次 |
| 最近记录: |