我怎样才能改变动作条的触摸效果颜色的Andr​​oid 3.0及更高版本 [英] How can I change the touch effect color of the ActionBar in Android 3.0 and higher

查看:127
本文介绍了我怎样才能改变动作条的触摸效果颜色的Andr​​oid 3.0及更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当你触摸的动作条项目变更的过渡效果的颜色。 在我的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及更高版本,即真正的动作条,我只是不知道如何做到这一点。

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?

推荐答案

本机操作栏使用theme属性 selectableItemBackground 行动项目的背景图。这应该是一个国家的列表绘制。

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:

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

这篇关于我怎样才能改变动作条的触摸效果颜色的Andr​​oid 3.0及更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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