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

Android examples for User Interface:View Property

Description

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

Demo Code


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

public class Main{
    /**//from  w  ww  .  j av  a 2 s .c  o  m
     * Safely sets elevation of a view by checking to
     * make sure View.setElevation() is supported
     *
     * @param view to set the elevation for
     * @param elevation to set the view to
     */
    public static void setElevation(View view, float elevation) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L) {
            view.setElevation(elevation);
        }
    }
}

Related Tutorials