当您触摸 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/