什么是动作条的像素大小?像素、大小、动作

2023-09-12 21:31:23 作者:没人替你坚强

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

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:

属性名称本身在平台中的/res/values/attrs.xml 在该平台的themes.xml选取该属性并分配一个值给它。 在步骤2中分配的值取决于不同器件尺寸,这在various dimens.xml文件的平台,即。 核心/ RES / RES /值-sw600dp / dimens.xml 的 The attribute name itself is defined in the platform's /res/values/attrs.xml The platform's themes.xml picks this attribute and assigns a value to it. 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