possible to change text size/color for ActionBar?

寵の児 提交于 2019-12-21 19:44:32

问题


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


回答1:


yes it is possible. You can do it through styles in this way:

<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>

and use it with:

 <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
 <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>


来源:https://stackoverflow.com/questions/16189877/possible-to-change-text-size-color-for-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!