4

Is there possible way to change size/color of ActionBar's title and subtitle?

I am using ActionBarSherlock for bridging between lower and higher versions. ActionBarSherlock provides way to customize text style in SherlockActionBarCompat, but there seems no way to make it in SherlockActionBarNative.

edit: added by Jake and removed by author

edit: Close to the solution:

<style name="resizeableTitleStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title.Inverse">
    <item name="android:textSize">@dimen/action_bar_title_text_size</item>
</style>

<style name="Theme.ResizeableActionBar" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/resizeableActionBarStyle</item>
    <item name="android:actionBarStyle">@style/resizeableActionBarStyle</item>
    <item name="actionBarSize">60dp</item>
    <item name="android:actionBarSize">60dp</item>
</style>

<style name="resizeableActionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="titleTextStyle">@style/resizeableTitleStyle</item>
    <item name="android:titleTextStyle">@style/resizeableTitleStyle</item>
</style>

Thank Jake, the author of ABS, for the help.

Now it's almost done, except that the actionBarSize can only be estimated for an approximate absolute dimension(60dp for my app) from quite a few trials; wrap_content causes API2.2 to expand the whole screen and does API4.2.2 exception thrown while parsing xml.

Addition:
when actionBarSize set as 0dp, the output is as (http://i.stack.imgur.com/xX4E1.png , low reputation to post images here directly): API2.2 in the left, the action bar occupies the whole screen without content, API4.2.2 in the right, content does without action bar.

when set as wrap_content, same output for API2.2, and exception thrown as: Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x10

4

1 回答 1

9

对的,这是可能的。您可以通过以下方式通过样式来做到这一点:

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Medium">
        <item name="android:textColor">@color/green_text_color</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/actionbar_textsize</item>
</style>

并将其用于:

 <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
 <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
于 2013-04-24T10:43:09.410 回答