2015-01-02 51 views
1

我目前正在尝试在我正在制作的Android应用上主题提醒对话框。 我可以通过API 19/20(KitKat)主题API 9(最小的应用程序)。API 21上的主题对话框(棒棒糖)Android

但是,我不能主题API 21(棒棒糖)正确。我不喜欢作为默认主题的灰白/浅灰色,所以我试图让整个背景变成白色。

Screenshot of dialog with default material light theme

我只能通过该对话框的布局的背景设置为白色做一定的量,并且还按钮背景给选择器,其为白色。

按钮后面还有一段空间(全部在底部),尽管它们仍然保持着浅灰色。我曾试着调查过是否可以通过主题buttonBarStyle属性来改变它,但没有任何运气。

下面是一些代码片段:

主题:

<style name="myTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:alertDialogStyle">@style/AlertDialogCustom</item> 
    </style> 

定制警告对话框主题:

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog"> 
     <item name="android:bottomBright">@color/white</item> 
     <item name="android:bottomDark">@color/white</item> 
     <item name="android:bottomMedium">@color/white</item> 
     <item name="android:centerBright">@color/white</item> 
     <item name="android:centerDark">@color/white</item> 
     <item name="android:centerMedium">@color/white</item> 
     <item name="android:fullBright">@color/white</item> 
     <item name="android:fullDark">@color/white</item> 
     <item name="android:topBright">@color/white</item> 
     <item name="android:topDark">@color/white</item> 
    </style> 

我已经尝试了对话主题,里面的一些这样的事情。 没有奏效:

<item name="android:background">@color/white</item> 
    <item name="android:colorBackground">@color/white</item> 
    <item name="android:buttonBarStyle">@style/CustomButtonBarStyle</item> 

CustomButtonBarStyle:

<style name="CustomButtonBarStyle" parent="@android:style/ButtonBar"> 
     <item name="android:background">@color/white</item> 
     <item name="android:divider">@color/white</item> 
    </style> 

任何帮助,将不胜感激!

+0

发现我需要使用 <项目名称=“机器人:alertDialogTheme”> @风格/ AlertDialogCustom 代替alertDialogStyle 不知道为什么这就不一样了,我本来期望无论是上班,因为风格一直工作到api 21. – XdrummerXboy

+0

你应该发布这个答案! –

+0

完成,谢谢@AdamS – XdrummerXboy

回答

2

发现我需要使用的

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

代替alertDialogStyle。不知道为什么它有所作为,我本来预计要么工作,因为风格工作一直到api 21.

我发布这个答案以及我有这个问题后,以及我伤口的解决方案(我可能有其他问题与上述答案,我不记得)重新创建整个对话框使用布局,并在布局中有自定义按钮。