// Retrieve the attribute value as a pixel offset TypedArray styledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.MyView); int pixelOffsetValue = styledAttributes.getDimensionPixelOffset(R.styleable.MyView_myAttribute, 0);
// Retrieve the attribute value as a pixel offset using a theme Resources.Theme theme = getContext().getTheme(); TypedArray styledAttributes = theme.obtainStyledAttributes(attrs, R.styleable.MyView, 0, 0); int pixelOffsetValue = styledAttributes.getDimensionPixelOffset(R.styleable.MyView_myAttribute, 0);In this example, we're using the getDimensionPixelOffset method to retrieve the value of a custom attribute called "myAttribute" using a theme object. The android.content.res package contains classes used to access resources in an Android application.