[英]Customizing default Theme.AppCompat.Dialog.Alert with android.support.v7.app.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>
在我的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的回復,鏈接詳細說明了解決方案,即在name屬性中包含和不包含“android:”前綴的聲明。
<item name="android:alertDialogTheme">@style/AlertDialog</item>
<item name="alertDialogTheme">@style/AlertDialog</item>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.