There are three constructors for custom Views, and their functions are different.
public MyView(Context context) { super(context); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); } public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
The first one is called when new object.
The second is called when the XML file is declared.
The system will only call the first two constructors by default. As for the call to the third constructor, we usually call it actively in the constructor ourselves.
The above are the three constructors of Android custom view introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!