Search code examples
androidandroid-custom-view

What is proper way to call obtainStyledAttributes() in Android custom views


What is the difference between

TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0);

and

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView, defStyleAttr, 0);

Solution

  • "defStyleAttr" is An attribute in the current theme that contains a reference to a style resource that supplies defaults values for the TypedArray. Can be 0 to not look for defaults.