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

本秂侑毒 提交于 2019-12-04 10:35:33

问题


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:

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

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!


回答1:


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!



来源:https://stackoverflow.com/questions/10890159/android-actionbarsherlock-is-there-any-way-to-keep-the-same-actionbar-height-b

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