当使用版本 21 的 appcompat 库时,?android:attr/actionBarSize
返回 48 个 dips,就好像它是 Holo 主题而不是 Material。事实上,它更大一些 - 56 个凹陷。
有没有人找到解决此问题的方法?
最佳答案
无需解决方法。如果您正在使用 ?android:attr/actionBarSize
,android 将在您当前使用的平台中查找值。显然,如果您运行的是低于 5.0 的 Android 版本,结果将是 48dp。
由于您在项目中使用 appcompat-v7
库,因此您应该使用 ?actionBarSize
。这将按预期返回 56dp,因为系统将在您的项目中查找值,该值具有因 appcompat-library 定义的 actionBarSize。
如果您想自己尝试这个,这里有一个小代码 fragment 来测试所描述的行为:
int[] textSizeAttr = new int[] { android.R.attr.actionBarSize, R.attr.actionBarSize };
TypedArray a = obtainStyledAttributes(new TypedValue().data, textSizeAttr);
float heightHolo = a.getDimension(0, -1);
float heightMaterial = a.getDimension(1, -1);
Log.d("DEBUG", "Height android.R.attr.: " + heightHolo + "");
Log.d("DEBUG", "Height R.attr.: " + heightMaterial + "");
注意:这将返回以像素为单位的大小。以我的 Nexus 5 为例,它目前运行 4.4,它为 android.R.attr.actionBarSize 返回 144px(48dp),为 R.attr 返回 168px (56dp)。 actionBarSize。
关于android - 新的 Theme.AppCompat ActionBar 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26449195/