Appcompat警报对话框“操作"按钮背景处于按下状态

编程入门 行业动态 更新时间:2024-10-07 09:24:11
本文介绍了Appcompat警报对话框“操作"按钮背景处于按下状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从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警报对话框“操作"按钮背景处于按下状态

本文发布于:2023-11-28 04:16:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按下   警报   对话框   按钮   状态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!