Actionbarsherlock的getHeight()返回0 [英] Actionbarsherlock getHeight() returns 0

查看:112
本文介绍了Actionbarsherlock的getHeight()返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Actionbarsherlock,我想将 PopupWindow 下方的操作栏。使用 showAtLocation()需要一个x与y偏移,因此,最好的y偏移将操作栏的高度。但是,当我打电话

I'm using Actionbarsherlock and I want to place a PopupWindow right below the action bar. Using the showAtLocation() takes an x and y offset, so ideally the y offset would be the height of the action bar. But when I call

int abHeight = getSupportActionBar().getHeight();

它返回零。我使用的是 SherlockFragmentActivity

下面是有关的code:

Here's the relevant code:

slidingLayout = inflater.inflate(R.layout.sliding_menu, null);
menuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT, Position.LEFT);
menuDrawer.setContentView(R.layout.activity_main);
menuDrawer.setMenuView(slidingLayout.findViewById(R.id.sliding_menu));

getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
int abHeight = getSupportActionBar().getHeight();

我已经看了遍,并不能找到一个类似的问题/答案,所以有没有人经历过这个?谢谢你。

I've looked all over and can't find a similar question/answer, so has anyone experienced this before? Thanks.

编辑:杰克的答案是正确的。为了获得该属性值我用这个帖子

Jake's answer was right on. In order to get that attribute value I used this post.

推荐答案

您可以阅读从 actionBarSize 主题属性操作栏的高度。根据设备配置的变化这所以确保你总是阅读它创建或重新创建你的活动时。

You can read the height of the action bar from the actionBarSize theme attribute. This changes based on the device configuration so make sure you are always reading it when your activity is created or recreated.

这篇关于Actionbarsherlock的getHeight()返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆