Appcompat 警报对话框操作按钮背景 按下状态 [英] Appcompat Alert Dialog Action button background On pressed state

查看:30
本文介绍了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) 如何改变图片中圆角(灰色)的 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)?

任何帮助都会很棒.

推荐答案

可以使用样式属性如

  • 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>

其中 dialogBu​​ttonSelector 是我们的自定义可绘制选择器.

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 警报对话框操作按钮背景 按下状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆