ActionBar 的像素大小是多少? [英] What is the size of ActionBar in pixels?

查看:43
本文介绍了ActionBar 的像素大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道 ActionBar 的确切大小(以像素为单位),以便应用正确的背景图像.

I need to know the exact size of ActionBar in pixels so to apply correct background image.

推荐答案

要在 XML 中检索 ActionBar 的高度,只需使用

To retrieve the height of the ActionBar in XML, just use

?android:attr/actionBarSize

或者如果您是 ActionBarSherlock 或 AppCompat 用户,请使用此

or if you're an ActionBarSherlock or AppCompat user, use this

?attr/actionBarSize

如果你在运行时需要这个值,使用这个

If you need this value at runtime, use this

final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
                    new int[] { android.R.attr.actionBarSize });
mActionBarSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();

如果您需要了解这是在哪里定义的:

If you need to understand where this is defined:

  1. 属性名称本身定义在平台的/res/values/attrs.xml
  2. 平台的themes.xml 选择此属性并为其分配一个值.
  3. 第 2 步分配的值取决于不同的设备尺寸,定义在 平台中的各种 dimens.xml 文件,即.core/res/res/values-sw600dp/dimens.xml
  1. The attribute name itself is defined in the platform's /res/values/attrs.xml
  2. The platform's themes.xml picks this attribute and assigns a value to it.
  3. The value assigned in step 2 depends on different device sizes, which are defined in various dimens.xml files in the platform, ie. core/res/res/values-sw600dp/dimens.xml

这篇关于ActionBar 的像素大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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