在Android Studio中编写如下语句时遇到了问题:1
TypedArray ta = obtainStyledAttributes(R.style.MyCustomStyle, attrs);
AS的错误提示是Excepted resource of type styleable。即要求obtainStyledAttributes方法的第一个参数必须是R.styleable.xxx中已定义的ID,如果传的这个int值没有被AS识别为style类型,那么就会出这个错误。
在我们已知参数是正确的情况下,解决这个警告提示的方法就是加suppress。即在这条语句或包含这条语句的方法上加“@SuppressWarnings(“ResourceType”)”即可。