造型行动项目背景ActionBarSherlock [英] Styling action item background ActionBarSherlock
问题描述
我一直在试图创建自己的行动项目,但它有鸭舌我不可能。
I've been trying to create my own action item, but it has benn impossible for me.
我什么tryind要做的,就是创建一个自定义操作项目布局(背景颜色为例),像大拇指行动起来吧。我只是想改变行动项目只为我的活动之一。
What I'm tryind to do, is creating a custom action item layout (color background for example), something like "Thumbs" action bar. I only want to change action items only for one of my activities.
我一直在玩安卓图标,安卓actionLayout属性操作菜单项..但我什么也没得到。
I've been playing with android:icon and android:actionLayout property for action menu items.. but I got nothing.
其实,我已经看到了计算器另一个线程,但它并没有帮助我......
Actually, I've seen another threads in StackOverflow, but it didn't help me ...
<一个href="http://stackoverflow.com/questions/10863080/building-actionmode-with-custom-layout-in-actionbarsherlock">Building ActionMode在ActionBarSherlock 自定义布局
<一个href="http://stackoverflow.com/questions/10062012/styling-actionbarsherlock-textcolor-of-the-action-items">styling ActionbarSherlock:的作用项文字颜色
任何想法?在此先感谢!
Any ideas? Thanks in advance!
推荐答案
要覆盖 ActionBarSherlock
主题,你应该继续这样的:
To override ActionBarSherlock
themes you should proceed like this:
打开值/ abs__themes.xml
从 ActionBarSherlock
库项目。你看,例如:
Open values/abs__themes.xml
from ActionBarSherlock
library project. You see for example:
<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 $ c中的项目$ C>您的项目中,并在其中加入:
When you have found the item you want to customize (actionBarItemBackground
in your case), you create your own themes.xml
inside your project, and add in it:
<style name="Custom.Theme.Sherlock" parent="@style/Theme.Sherlock">
<item name="actionBarItemBackground">@drawable/my__item_background_holo_dark</item>
</style>
这将覆盖默认 Theme.Sherlock
,设置自定义 actionBarItemBackground
。
This overrides the default Theme.Sherlock
, setting a custom actionBarItemBackground
.
现在,而不是使用 Theme.Sherlock
在你的活动,你应该使用 setTheme(R.style.Custom_Theme_Sherlock)
。您可能还需要覆盖其他两个主题( Theme.Sherlock.Light
和 Theme.Sherlock.Light.DarkActionBar
)
Now, instead of using Theme.Sherlock
in your activity you should use setTheme(R.style.Custom_Theme_Sherlock)
. You may also want to override the other two themes (Theme.Sherlock.Light
and Theme.Sherlock.Light.DarkActionBar
)
另外一个技巧,这里是由 ActionBarSherlock
的默认操作项目的背景(在holo_light)可绘制的选择,它采用9补丁PNG可绘制:
One more tip, here is the drawable selector used by ActionBarSherlock
for the default action item background (in holo_light), it uses 9-patch png drawables:
<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" />
有关其他基本自定义,你可以使用这个<一href="http://jgilfelt.github.com/android-actionbarstylegenerator/#name=example&compat=holo&theme=light&actionbarstyle=solid&backColor=E4E4E4,100&secondaryColor=D6D6D6,100&tertiaryColor=F2F2F2,100&accentColor=33B5E5,100">tool,它生成的风格给你。
For other basic customizing, you can use this tool, it generates styles for you.
这篇关于造型行动项目背景ActionBarSherlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!