您好我确实为AlertDialog创建了主题/样式。但是我确实遇到按钮栏的问题,即使我设置了背景颜色,它仍然是灰色的。酒吧内的按钮也没有像我预期的那样填满酒吧。我尝试了几件事,但我无法完成这件事。
<style name="MyBorderlessButton">
<!-- Set background drawable and text size of the buttons here -->
<item name="android:background">@drawable/button_dark_border</item>
<item name="android:textColor">@color/white</item>
</style>
<style name="MyButtonBar" parent="@android:style/ButtonBar">
<!-- Define a background for the button bar and a divider between the buttons here -->
<item name="android:divider">?android:attr/dividerVertical</item>
<item name="android:dividerPadding">1dp</item>
<item name="android:showDividers">middle</item>
<item name="android:padding">3dp</item>
<item name="android:background">@color/transparent</item>
</style>
<style name="MyAlertDialogTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
</style>
<style name="MyAlertTextAppearance">
<!-- Set text size and color of title and message here -->
<item name="android:textColor">@color/white</item>
</style>
<style name="MyAlertDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowTitleStyle">@style/MyAlertDialogTitle</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
<item name="android:windowIsFloating">true</item>
<item name="android:textAppearanceMedium">@style/MyAlertTextAppearance</item>
<!--
If you don't want your own button bar style use
@android:style/Holo.Light.ButtonBar.AlertDialog
and
?android:attr/borderlessButtonStyle
instead of @style/MyButtonBar and @style/MyBorderlessButton
-->
<item name="android:buttonBarStyle">@style/MyButtonBar</item>
<item name="android:buttonBarButtonStyle">@style/MyBorderlessButton</item>
</style>
<style name="MyAlertDialogStyle">
<!-- Define background colors of title, message, buttons, etc. here -->
<item name="android:background">@color/drawer_background</item>
</style>
button_dark_border:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/drawer_background" />
<stroke android:width="1dip" android:color="@color/white"/>
</shape>
如何让Button栏也变黑,Button再次填充AlertDialog?
答案 0 :(得分:0)
我修复了更新样式文件的问题。一段时间后,我发现父属性阻止了我的一些更改。这是我的styles.xml现在
<style name="Theme.PeeDeeTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:alertDialogTheme">@style/PeeDeeAlertDialogTheme</item>
<item name="android:alertDialogStyle">@style/PeeDeeAlertDialogStyle</item>
</style>
<style name="MyBorderlessButton">
<!-- Set background drawable and text size of the buttons here -->
<item name="android:background">@color/primarycolor_dark</item>
<item name="android:textColor">@color/white</item>
<!--
Setting the weight as follows should result in equally wide buttons filling the alert dialog width,
but instead they span further out of the dialog, breaking in multiple lines though
-->
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">15dp</item>
<item name="android:height">@null</item>
</style>
<style name="MyButtonBar">
<!-- Define a background for the button bar and a divider between the buttons here -->
<item name="android:divider">?android:attr/listDivider</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:showDividers">none</item>
<item name="android:padding">0dp</item>
<item name="android:background">@color/transparent</item>
<!-- Making sure, the button bar uses parent width and is not restricted in height -->
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:height">@null</item>
<item name="android:minHeight">@null</item>
</style>
<style name="MyAlertDialogTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textColor">@color/defaultcolor_drawer</item>
</style>
<style name="MyAlertTextAppearance">
<!-- Set text size and color of title and message here -->
<item name="android:textColor">@color/white</item>
</style>
<style name="MyAlertDialogTheme">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowTitleStyle">@style/MyAlertDialogTitle</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
<item name="android:windowIsFloating">true</item>
<item name="android:textAppearanceMedium">@style/MyAlertTextAppearance</item>
<item name="android:buttonBarStyle">@style/MyButtonBar</item>
<item name="android:buttonBarButtonStyle">@style/MyBorderlessButton</item>
<item name="android:panelBackground">@color/transparent</item>
</style>
<style name="MyAlertDialogStyle">
<!-- Define background colors of title, message, buttons, etc. here -->
<item name="android:fullDark">@color/drawer_background</item>
<item name="android:topDark">@color/drawer_background</item>
<item name="android:centerDark">@color/drawer_background</item>
<item name="android:bottomDark">@color/transparent</item>
<item name="android:fullBright">@color/drawer_background</item>
<item name="android:topBright">@color/drawer_background</item>
<item name="android:centerBright">@color/drawer_background</item>
<item name="android:bottomBright">@color/transparent</item>
<item name="android:bottomMedium">@color/transparent</item>
<item name="android:centerMedium">@color/drawer_background</item>
<item name="android:panelBackground">@color/drawer_background</item>
</style>