我需要知道动作栏的像素大小,以便应用正确的背景图像。
当前回答
在我的Galaxy S4上有> 441dpi > 1080 x 1920 > 使用getResources()获取动作栏高度。我得到144像素。
使用公式px = dp x (dpi/160),我使用的是441dpi,而我的设备位于 在类别480dpi。这样就证实了这个结果。
其他回答
如果你在使用ActionBarSherlock,你可以用
@dimen/abs__action_bar_default_height
蜂窝样本之一是指?android:attr/actionBarSize
我这样做是为了自己,这个帮手方法应该对其他人有用:
private static final int[] RES_IDS_ACTION_BAR_SIZE = {R.attr.actionBarSize};
/**
* Calculates the Action Bar height in pixels.
*/
public static int calculateActionBarSize(Context context) {
if (context == null) {
return 0;
}
Resources.Theme curTheme = context.getTheme();
if (curTheme == null) {
return 0;
}
TypedArray att = curTheme.obtainStyledAttributes(RES_IDS_ACTION_BAR_SIZE);
if (att == null) {
return 0;
}
float size = att.getDimension(0, 0);
att.recycle();
return (int) size;
}
在Android 3.2的framework-res.apk的反编译源代码中,res/values/styles.xml包含:
<style name="Theme.Holo">
<!-- ... -->
<item name="actionBarSize">56.0dip</item>
<!-- ... -->
</style>
3.0和3.1似乎是一样的(至少从AOSP来看)…
如果你正在使用最近的v7 appcompat支持包中的兼容ActionBar,你可以使用
@dimen/abc_action_bar_default_height
文档
推荐文章
- 从资产中读取文件
- 在不活动的地方调用getLayoutInflater()
- 设置Android布局元素的背景颜色
- 错误:'keytool'不能被识别为内部或外部命令、可操作程序或批处理文件
- 在应用程序本身中更改Locale
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置
- 如何模拟Android杀死我的进程
- 禁用EditText闪烁光标
- Android Eclipse -无法找到*.apk
- 设置TextView文本从html格式的字符串资源在XML
- 如何允许所有网络连接类型HTTP和HTTPS在Android(9)馅饼?
- Android加载JS包失败