转自http://igoesolutions.com/blog/2011/06/20/custom-view-is-not-using-the-2-or-3-argument-view-constructors-xml-attributes-will-not-work/

 

写三个构造函数就OK了:

public class ExtendedClass extends Button {

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

 

相关文章: