我需要知道动作栏的像素大小,以便应用正确的背景图像。
当前回答
在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来看)…
其他回答
课程摘要通常是一个很好的开始。我认为getHeight()方法就足够了。
编辑:
如果你需要宽度,它应该是屏幕的宽度(对吧?),可以像这样收集。
我这样做是为了自己,这个帮手方法应该对其他人有用:
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;
}
@AZ13的回答很好,但根据Android设计指南,动作栏至少应该是48dp高。
蜂窝样本之一是指?android:attr/actionBarSize
在我的Galaxy S4上有> 441dpi > 1080 x 1920 > 使用getResources()获取动作栏高度。我得到144像素。
使用公式px = dp x (dpi/160),我使用的是441dpi,而我的设备位于 在类别480dpi。这样就证实了这个结果。
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件