I have these two elements in my size definitions:
<dimen name="toolbar_search_extended_height">158dp</dimen>
<dimen name="toolbar_search_normal_height">?attr/actionBarSize</dimen>
Now I want to get the actual value in pixels at runtime:
height = getResources().getDimensionPixelOffset(R.dimen.toolbar_search_extended_height);
height = getResources().getDimensionPixelOffset(R.dimen.toolbar_search_normal_height);
The first call gives any value of 158dp in pixels on the device.
The second call gives a NotFoundException:
android.content.res.Resources$NotFoundException: Resource ID
Type 0x2: TypedValue#TYPE_ATTRIBUTE:
public static final int TYPE_ATTRIBUTE = 0x02;
What is the preferred method for dereferencing values dimen, which can be either actual values ββor references to stylized attributes?
source
share