设置操作项背景 ActionBarSherlock

2024-06-06

我一直在尝试创建自己的行动项目,但这对我来说是不可能的。

我想做的是创建一个自定义操作项布局(例如颜色背景),例如“拇指”操作栏。我只想更改我的一项活动的操作项。

我一直在玩操作菜单项的 android:icon 和 android:actionLayout 属性..但我什么也没得到。

实际上,我在 StackOverflow 中看到了另一个线程,但它对我没有帮助......

在 ActionBarSherlock 中使用自定义布局构建 ActionMode https://stackoverflow.com/questions/10863080/building-actionmode-with-custom-layout-in-actionbarsherlock

样式 ActionbarSherlock:操作项的文本颜色 https://stackoverflow.com/questions/10062012/styling-actionbarsherlock-textcolor-of-the-action-items

有任何想法吗?提前致谢!


覆盖ActionBarSherlock主题你应该像这样进行:

Open values/abs__themes.xml from ActionBarSherlock图书馆项目。例如你会看到:

<style name="Theme.Sherlock" parent="Sherlock.__Theme">
    <!-- Action bar styles (from Theme.Holo) -->
    <item name="actionDropDownStyle">@style/Widget.Sherlock.Spinner.DropDown.ActionBar</item>
    <item name="actionButtonStyle">@style/Widget.Sherlock.ActionButton</item>
    <item name="actionOverflowButtonStyle">@style/Widget.Sherlock.ActionButton.Overflow</item>
    <item name="actionModeBackground">@drawable/abs__cab_background_top_holo_dark</item>
    <item name="actionModeSplitBackground">@drawable/abs__cab_background_bottom_holo_dark</item>
    <item name="actionModeCloseDrawable">@drawable/abs__ic_cab_done_holo_dark</item>
    <item name="actionBarTabStyle">@style/Widget.Sherlock.ActionBar.TabView</item>
    ...
    // Here is what you wanted
    <item name="actionBarItemBackground">@drawable/abs__item_background_holo_dark</item>
    ...

当您找到您想要定制的项目时(actionBarItemBackground在你的情况下),你创建自己的themes.xml在您的项目中,并添加:

<style name="Custom.Theme.Sherlock" parent="@style/Theme.Sherlock">
    <item name="actionBarItemBackground">@drawable/my__item_background_holo_dark</item>
</style>

这会覆盖默认值Theme.Sherlock,设置自定义actionBarItemBackground.

现在,而不是使用Theme.Sherlock在你的活动中你应该使用setTheme(R.style.Custom_Theme_Sherlock)。您可能还想覆盖其他两个主题(Theme.Sherlock.Light and Theme.Sherlock.Light.DarkActionBar)

还有一点提示,这是使用的可绘制选择器ActionBarSherlock对于默认的操作项背景(在 Holo_light 中),它使用 9-patch png 可绘制对象:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- 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/abs__list_selector_disabled_holo_light" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/abs__list_selector_disabled_holo_light" />
<item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/abs__list_selector_background_transition_holo_light" />
<item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/abs__list_selector_background_transition_holo_light" />
<item android:state_focused="true"                                                             android:drawable="@drawable/abs__list_focused_holo" />
<item                                                                                          android:drawable="@android:color/transparent" />

对于其他基本定制,您可以使用此,它会为您生成样式。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

设置操作项背景 ActionBarSherlock 的相关文章

随机推荐