我正在尝试 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) 如何改变图片中圆角(灰色)的 statePressed 颜色?
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)?
任何帮助都会很棒.
可以使用样式属性如
buttonBarButtonStylebuttonBarNegativeButtonStylebuttonBarNeutralButtonStylebuttonBarPositiveButtonStyle例子:
<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 粗体.
dialog_button style can inherit through Widget.AppCompat.Button.ButtonBar.AlertDialog but I found that it has missing styles like textStyle bold.
这篇关于Appcompat 警报对话框操作按钮背景 按下状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 GPS 获取用户的当前位置Get user#39;s current location using GPS(使用 GPS 获取用户的当前位置)
requestLocationUpdate() 抛出的 IllegalArgumentExceptionIllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 抛出的 IllegalArgumentException)
LocationManager 的 getLastKnownLocation 有多可靠,多久更How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新
如何检测位置提供者?GPS 或网络提供商How to detect Location Provider ? GPS or Network Provider(如何检测位置提供者?GPS 或网络提供商)
在应用启动期间获取当前位置Get current location during app launch(在应用启动期间获取当前位置)
locationManager.getLastKnownLocation() 返回 nulllocationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)