2

I extended the class ImageView and added some custom parameters. I succeed to get these custom parameters from my code, using the method Context.getTheme().obtainStyledAttributes().

What I need is to access the standard parameters of the ImageView object, such as android:src and android:background. I know it exist the class android.R.styleable.* which I could use to get those parameters, but that class has been deprecated (and is not visible anymore). What can I do to access those android parameters?

Massimo
  • 3,436
  • 4
  • 40
  • 68

1 Answers1

-1

While I’m not sure how to extract parent values from a TypedArray, you’re able to access them with appropriate getters, e.g.:

public class MyImageView extends ImageView {

    public MyImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        final TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.whatever);
        try {
            // get custom attributes here
        } finally {
            array.recycle();
        }

        // parent attributes
        final Drawable background = getBackground();
        final Drawable src = getDrawable();

        // etc.
    }

}

It's not exactly what you're looking for, but it might help.

Tadej
  • 2,901
  • 1
  • 17
  • 23
  • This is the code for getting the custom attributes. I am not able to retrieve the standard ones... – Massimo Mar 24 '14 at 15:57
  • I'm not exactly sure what you mean by _standard_ ones. Is the code after 'parent attributes' comment not what you're trying to get? – Tadej Mar 24 '14 at 15:59
  • I am trying to get the android attributes, such as android:src, android:background, android:layout_width, etc... – Massimo Mar 24 '14 at 16:31