Jus*_*sLi 1 android android-layout android-view
如果我使用不属于Android 2.3.3 API的视图类(如setLayerType)的API,如何让我的Android应用程序与以前的Android版本兼容?我可以用这种方法代替什么?
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
// only for gingerbread and newer versions
// setLayerType
}
Run Code Online (Sandbox Code Playgroud)
或通过反思
try {
Method setLayerTypeMethod = mWebView.getClass().getMethod("setLayerType", new Class[] {int.class, Paint.class});
if (setLayerTypeMethod != null)
setLayerTypeMethod.invoke(yourView, new Object[] {LAYER_TYPE_SOFTWARE, null});
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)