Please help me out of the insanity!
The code below works and sets the background of my custom view as I want:
public class MyLayout extends LinearLayout {
public MyLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0, R.style.MyStyle);
}
//Omissions
}
But it gives:
Call requires API level 21 (current min is 19): new android.widget.LinearLayout
I did some code which manually extracts the attributes from the style, but it is not dynamic - so if the style changes later by adding attributes, things will have to be maintained.
I've read the quote below, but do not quite understand the interaction with the 'theme':
defStyleAttr An attribute in the current theme that contains a reference to a style resource that supplies defaults values for the StyledAttributes. Can be 0 to not look for defaults.
defStyleRes A resource identifier of a style resource that supplies default values for the StyledAttributes, used only if defStyleAttr is 0 or cannot be found in the theme. Can be 0 to not look for defaults.
The following does nothing:
public class MyLayout extends LinearLayout {
public MyLayout(Context context, AttributeSet attrs) {
super(context, attrs, R.style.MyStyle);
}
//Omissions
}
What have I done wrong? How do I simply style my custom component with a background color?