如何让动作条的高度? [英] How to get the ActionBar height?

查看:135
本文介绍了如何让动作条的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的动作条(使用福尔摩斯)每次创建活动的时间(特别处理轮换配置更改,其中的动作条的高度可能会改变高度)。

I am trying to get the height of the ActionBar (using Sherlock) every time an activity is created (specially to handle configuration changes on rotation where the ActionBar height might change).

为此,我使用的方法 ActionBar.getHeight()这只能当动作条显示。

For this I use the method ActionBar.getHeight() which works only when the ActionBar is shown.

在第一个活动是第一次创建的,我可以叫的getHeight() onCreateOptionsMenu 回调。但这种方法不之后调用

When the first activity is created for the first time, I can call getHeight() in the onCreateOptionsMenu callback. But this method is not called after.

所以我的问题是我何时可以调用的getHeight()和放心,它不会返回0? 或者,如果它是不可能的,我怎么能设置动作条的高度?

So my question is when can I call getHeight() and be assured that it doesn't return 0? Or if it is not possible, how can I set the height of the ActionBar ?

推荐答案

虽然@鸟人的回答是一个选项,如果你想明确地控制动作条大小有一种方法把它拉起来没有锁定,我发现支持大小文档。这是一个有点笨拙,但它为我工作。你需要一个环境,这个例子是有效的一个活动。

While @birdy's answer is an option if you want to explicitly control the ActionBar size there is a way to pull it up without locking the size that I found in support documentation. It's a little awkward but it's worked for me. You'll need a context, this example would be valid in an Activity.

// Calculate ActionBar height
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
    actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}

这篇关于如何让动作条的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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