如何在 Android 3.0 及更高版本中更改 ActionBar 的触摸效果颜色 [英] How can I change the touch effect color of the ActionBar in Android 3.0 and higher

查看:22
本文介绍了如何在 Android 3.0 及更高版本中更改 ActionBar 的触摸效果颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to change the color of the rollover effect when you touch an ActionBar Item. On my Galaxy Nexus with 4.0.2 it's kind of a turquoise color shading which I want to be in a different color.

明确地说,我在这里谈论的是 ActionBar 项,而不是导航选项卡.

To be clear, I am talking about ActionBar items here, not navigation tabs.

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

I got it working under the compatibility library, but for Android 3.0 and higher, i.e. the "real" ActionBar, I just can't figure out how to do this.

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

Does anyone knows if and how this can be achieved?

推荐答案

原生操作栏使用主题属性 selectableItemBackground 进行操作项背景绘制.这应该是一个 state-list drawable.

The native action bar uses the theme attribute selectableItemBackground for action item background drawing. This should be a state-list drawable.

这是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:

And its drawable 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 3.0 及更高版本中更改 ActionBar 的触摸效果颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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