Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android (ActionBarSherlock) Is there any way to keep the same ActionBar height both in portrait and landscape?

I have been working with the ActionBar and ActionBarSherlock for the last few days, and i am having some issues when filling some information in the ActionBar.

When the application runs in portrait mode, the ActionBar looks fine, and all the data can be displayed, for example:

ActionBar in portrait mode

But when i switch the app to be displayed in landscape, some of the data is cropped:

ActionBar in landscape mode

You can notice how both the status icon and the email has been cropped due to the new height of the ActionBar.

In this case, i want to keep the same size for portrait and landscape so the app can look fine. I can't reduce the font size of the action bar title, since it may include other icons.

The way i´m putting these icons in the action bar title and subtitle is by using Html.fromHtml

Any ideas to solve this problem? I am using the ActionBarSherlock library!

like image 200
Alvaro Luis Bustamante Avatar asked Jun 05 '12 00:06

Alvaro Luis Bustamante


1 Answers

One, probably not too pretty approach, could be to override the default height values for the ActionBar in dimens.xml.

E.g. the default value in portrait is:

<dimen name="abs__action_bar_default_height">48dip</dimen>

And in landscape:

<dimen name="abs__action_bar_default_height">40dip</dimen>

There might be a cleaner way to do it, but I have to admit I know too little about the internals of ActionBarSherlock for that.


Edit: Come to think of it, this probably won't work when the native ActionBar is being used on ICS, since the height will then resolve to the platform value in ?android:attr/actionBarSize. I'd recommend you wait for a better suggestion, e.g. from Jake himself.

Second edit: After Jake's reply it seems like all you need to do to make it work with ActionBarSherlock on both ICS and pre-ICS devices is add the following to your app's theme:

<item name="actionBarSize">@dimen/some_value</item>
<item name="android:actionBarSize">@dimen/some_value</item> 

You can then add the actual values in the relevant portrait/land resource buckets.

Third edit [thanks alvarolb]: XML Example for the style:

<?xml version="1.0" encoding="utf-8"?>
<resources>   
    <style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarSize">48dip</item>
        <item name="android:actionBarSize">48dip</item> 
    </style> 
</resources>

And in the corresponding activity, set this new style

android:theme="@style/Theme.Styled"

and.. it works!

like image 120
MH. Avatar answered Oct 27 '22 23:10

MH.