Backlight87
10/16/2017 - 10:36 AM

bug-fix-Error: Expected resource of type

bug-fix-Error: Expected resource of type 这个错误一般是出现在我们获取资源(自定义view)时,获取drawable 或者其他值的时候



解决方案:
在方法头加上@SuppressWarnings("ResourceType")

@SuppressWarnings("ResourceType")
public void initView() {
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    boolean hasBottomLine = ta.getBoolean(0, false);
    boolean hasTopLine = ta.getBoolean(1, false);
    ta.recycle();
}