Android 在使用自定義控件的時候,會提示這樣的錯誤資訊:
not using the 2- or 3-argument View constructors; XML attributes will not work
往是由于你隻定義了一個構造函數,解決方法就是至少要定義兩個構造函數
處理如下:
public SlideButton(Context context) {
super(context);
initBitmap();
}
public SlideButton(Context context, AttributeSet attrs){
super(context,attrs);
initBitmap();
}
public SlideButton(Context context,AttributeSet attrs,int defStyle){
super(context,attrs,defStyle);
initBitmap();
}
如果你隻寫了第一個構造函數,那麼就會扡這個錯誤,至少要寫上第二個或第三個構造函數才可以!!