什么是动作条的像素大小? [英] What is the size of ActionBar in pixels?

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

问题描述

我需要知道的动作条中的像素的确切大小,以应用正确的背景图片。

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

推荐答案

要检索的动作条在XML的高度,只要使用

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. 属性名称本身在平台中的<定义href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/attrs.xml">/res/values/attrs.xml
  2. 在该平台的<一个href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml">themes.xml选取该属性并分配一个值给它。
  3. 在步骤2中分配的值取决于不同器件尺寸,这在<限定href="https://github.com/android/platform_frameworks_base/search?q=action_bar_default_height&type=$c$c">various dimens.xml文件的平台,即。 核心/ RES / RES /值-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

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

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