1

Android 2.3.3 API にない setLayerType などのビュー クラスの API を使用する場合、Android アプリを以前の Android バージョンと互換性を持たせるにはどうすればよいですか? このメソッドを何に置き換えることができますか?

4

2 に答える 2

5
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
     // only for gingerbread and newer versions
//        setLayerType
}

または反射を通して

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();
}
于 2013-06-07T18:25:07.513 に答える