The method initializeScrollbars(TypedArray) is undefined for the type PLA_AbsListView
这个错误,很多人认为是 API版本太低,initializeScrollbars这个函数没有办法用,
真正的解决方法是采用:反射的机制来搞定,因为,我们知道方法名,方法的参数,所以就可以这样做,
final TypedArray a = context.getTheme().obtainStyledAttributes(new int[0]);
try {
// initializeScrollbars(TypedArray)
Method initializeScrollbars = android.view.View.class.getDeclaredMethod("initializeScrollbars", TypedArray.class);
initializeScrollbars.invoke(this, a);
} catch (Exception e) {
e.printStackTrace();
}
这种方法是最有效果的,
一般这种错误是出现在自定义的view中的构造函数里面。
Use reflection to invoke initializeScrollbars()
in your custom view's constructor. This could fail in future API versions if the method initializeScrollbars()
is actually removed or renamed. For example:
In your custom view (e.g. MyCustomView.java
):
public MyCustomView(Context context) {
super(context);
// Need to manually call initializedScrollbars() if instantiating view programmatically
final TypedArray a = context.getTheme().obtainStyledAttributes(new int[0]);
try {
// initializeScrollbars(TypedArray)
Method initializeScrollbars = android.view.View.class.getDeclaredMethod("initializeScrollbars", TypedArray.class);
initializeScrollbars.invoke(this, a);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
a.recycle();
}