Programming Tips - Android: use reflection to call View.setZ()

Date: 2020apr28 OS: Android Language: Java Q. Android: use reflection to call View.setZ() A.
void setZ(View view, final float zindex) { if (Build.VERSION.SDK_INT < 21) return; try { Method setZ = view.getClass().getMethod("setZ", float.class); setZ.invoke(view, zindex); } catch (Exception ex) { Log.i(LOG_TAG, "setZ: " + ex.toString()); } }
Or you can use ViewCompat:
ViewCompat.setZ(view, zindex);