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

对着背影说爱祢 提交于 2019-12-03 06:11:22

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!

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