0

我有一些关于如何自定义选项卡和菜单项的问题 - 如何设置徽标和选项卡之间的边距(它们都在一行中)以及如何在只有图标的菜单项之间放置垂直分隔符?(问题是当您将菜单项显示为文本或图标+文本时有垂直分隔符,但仅在图标的情况下没有)关于菜单项分隔符的另一件事是如何将此分隔符放在每个图标之前?

我看过所有的 actionbarsherlock 示例,其中有很多样式,并检查了有关它的其他资源,但我没有找到如何自定义这些东西。

4

1 回答 1

0

Margin between tabs and logo

Unless you create a custom view with your custom tab implementation there is only one way I can figure out to create a space between tabs and logo (assuming that the title is hidden) is setting the tab bar's left padding. For this your theme has to contain:

<style name="MyTheme" parent="@style/Theme.Sherlock">
    <item name="actionBarTabBarStyle">@style/MyTabBarStyle</item>
    <item name="android:actionBarTabBarStyle">@style/MyTabBarStyle</item>
</style>

The MyTabBarStyle has to contain:

<style name="MyTabBarStyle" parent="Widget.Sherlock.ActionBar.TabBar">
    <item name="android:paddingLeft">@dimen/my_left_padding</item>
</style>

Note that you have to set this version of MyTabBarStyle in the proper place to be displayed only when the tabs are placed in the main action bar (which happens usually in the landscape orientation configuration), so you should place it in res/values-land/styles.xml.

Menu items' dividers

You mentioned correctly, that it is a problem to create dividers when the menu items are displayed as icons. You can still use little trick to do it - encode the dividers into action button backgrounds. If you use 9-patch drawables like this (scaled for better visibility):

enter image description here

then a green dividers will be created (naturally you should also create versions for other states).

To set the background, you have to define android:actionButtonStyle in the theme:

<style name="MyTheme" parent="@style/Theme.Sherlock">
    <item name="actionButtonStyle">@style/MyActionButtonStyle</item>
    <item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
</style>

And the style has to have background defined:

<style name="MyActionButtonStyle" parent="@style/Widget.Sherlock.ActionButton">
    <item name="android:background">@drawable/my_actionbutton_bg</item>
</style>

With this solution, you can place the divider before each item. Note that if overflow icon is displayed, you should probably define a similar background for android:actionOverflowButtonStyle.

A different solution to the problem might be to define android:actionLayout for menu items. There you can define your custom layout for each menu item.

于 2013-01-03T11:17:55.803 回答