问题描述
我正在尝试从appcompat v7 22.1.1中新建AlertDialog
.
I am trying new AlertDialog
from appcompat v7 22.1.1.
它在图像中的效果很好(在所有android版本中).
It works pretty well (In all android versions) as in image.
AlertDialog的样式是这个. (目前,我使用的是硬编码的颜色值,而不是颜色资源)
Style for AlertDialog is this. (For now I am using hardcoded color values instead of color resources)
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#111111</item>
<item name="colorPrimary">#00ddff</item>
<item name="colorAccent">#0044aa</item>
<item name="colorButtonNormal">#00aaaa</item>
<item name="colorControlHighlight">#00ddff</item>
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
</style>
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorAccent">#0044aa</item>
<item name="android:background">#ffffff</item>
<item name="android:textColorPrimary">#000000</item>
<item name="android:windowTitleStyle">@style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle">
<item name="android:textColor">#0044aa</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Title</item>
</style>
我的问题是,
1)如何更改状态在图像中四舍五入为圆形(灰色)的已按下颜色?
2)android> = 21中没有按下的颜色,这有什么用呢?
2) No pressed color is there in android >= 21 , what is hack for this ?
3)如何为操作按钮设置不同颜色(可以)?
3) How can I have different colors of action buttons (Is it possible)?
任何帮助都会很棒.
推荐答案
您可以使用样式属性,例如
You can use style attributes like
-
buttonBarButtonStyle
-
buttonBarNegativeButtonStyle
-
buttonBarNeutralButtonStyle
-
buttonBarPositiveButtonStyle
buttonBarButtonStyle
buttonBarNegativeButtonStyle
buttonBarNeutralButtonStyle
buttonBarPositiveButtonStyle
示例:
<style name="dialog_theme" parent="Theme.AppCompat.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">@style/dialog_button.negative</item>
<item name="buttonBarPositiveButtonStyle">@style/dialog_button.positive</item>
</style>
<style name="dialog_button">
<item name="android:textStyle">bold</item>
<item name="android:minWidth">64dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:background">@drawable/dialogButtonSelector</item>
</style>
<style name="dialog_button.negative">
<item name="android:textColor">#f00</item>
</style>
<style name="dialog_button.positive">
<item name="android:layout_marginLeft">8dp</item>
<item name="android:textColor">#00f</item>
</style>
dialogButtonSelector
是我们自定义的可绘制选择器.
Where dialogButtonSelector
is our custom drawable selector.
不幸的是,在dialog_button
上设置背景会破坏我们的填充和边距,因此我需要再次设置它.
Unfortunatelly setting background on dialog_button
destroy our paddings and margins so I need to set it again.
dialog_button
样式可以通过Widget.AppCompat.Button.ButtonBar.AlertDialog
继承,但是我发现它缺少textStyle
bold
之类的样式.
dialog_button
style can inherit through Widget.AppCompat.Button.ButtonBar.AlertDialog
but I found that it has missing styles like textStyle
bold
.
这篇关于Appcompat警报对话框“操作"按钮背景处于按下状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!