Android 自定义控件build时提示Custom view * is not using the 2- or 3-argument View constructors; XML attribut

如果你的控件继承自view那么需要写上三个构造函数,其它的可以查看源码,只要把全部的继承函数都写上去就可以了。

View的三个继承函数是:


public WiperSwitch(Context context) {
		super(context);
		init();
	}

	public WiperSwitch(Context context, AttributeSet attrs){
		super(context,attrs);
		init();
	}

	public WiperSwitch(Context context,AttributeSet attrs,int defStyle){
		super(context,attrs,defStyle);
		init();
	}

说明:这里的init是我的控件要执行的一个默认方法,其它的控件同理,只要写上全部的构造函数就不会把这样的错误了。

(完)

你可能感兴趣的:(android,继承)