Safely gets elevation of a view by checking to make sure View.getElevation() is supported - Android User Interface

Android examples for User Interface:View Property

Description

Safely gets elevation of a view by checking to make sure View.getElevation() is supported

Demo Code


import android.os.Build;
import android.view.View;

public class Main{
    /**//from w  w  w.  j a v a  2  s. com
     * Safely gets elevation of a view by checking to
     * make sure View.getElevation() is supported
     *
     * @param view to get elevation for
     * @return view.getElevation() if supported, otherwise returns -1
     */
    public static float getElevation(View view) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L) {
            return view.getElevation();
        } else {
            return -1;
        }
    }
}

Related Tutorials