4
我最近在我的应用程序中将AlertDialog
实例切换为使用android.support.v7.app.AlertDialog
,但在将自定义主题和样式应用于警报对话框。使用android.support.v7.app.AlertDialog自定义默认Theme.AppCompat.Dialog.Alert
在我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
指定主题构造函数?
阅读它http://stackoverflow.com/questions/18307622/applying-a-theme-to-v7-support-action-bar。它对你有帮助吗? –