android - 如何在 Android 3.0 及更高版本中更改 ActionBar 的触摸效果颜色

标签 android colors touch android-actionbar

当您触摸 ActionBar 项目时,我正在尝试更改翻转效果的颜色。 在我的 Galaxy Nexus 4.0.2 上,它是一种绿松石色阴影,我想使用不同的颜色。

为了清楚起见,我在这里谈论的是 ActionBar 项,而不是导航选项卡。

我让它在兼容性库下工作,但对于 Android 3.0 及更高版本,即“真正的”ActionBar,我就是不知道如何做到这一点。

有谁知道这是否以及如何实现?

最佳答案

native 操作栏使用主题属性 selectableItemBackground 进行操作项背景绘制。这应该是一个可绘制的状态列表。

这是 Theme.Holo 中的声明:

<style name="Theme.Holo">
    <!-- bunch of things -->
    <item name="android:selectableItemBackground">@android:drawable/item_background_holo_dark</item>
    <!-- bunch of things -->
</style>

及其可绘制的 XML:

<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:exitFadeDuration="@android:integer/config_mediumAnimTime">

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_dark" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_disabled_holo_dark" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" />
    <item android:state_focused="true"                                                             android:drawable="@drawable/list_focused_holo" />
    <item                                                                                          android:drawable="@color/transparent" />
</selector>

关于android - 如何在 Android 3.0 及更高版本中更改 ActionBar 的触摸效果颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9019512/

相关文章:

r - 如何用特定颜色表示等高线图(fill.contour)中的最佳区域?

objective-c - 适用于 iOS 的 GluUnProject

横向模式下的 iPhone UITextField

qt - Windows 7 中带有 Qt/QML 应用程序的自定义触摸行为

android - 部分信任环境中的异步 CTP

php - Android 的 Json 输出

java - 显示具有多个航点的两点之间的路线 Android Here Map Lite Edition

actionscript-3 - 更改影片剪辑 Actionscript 3 的填充颜色

javascript - 从颜色词中获取颜色代码

android - 如何为水平recyclerview制作页面指示器