Convenience method for setting the ripple hotspot during an onTouch event for Lollipop+ devices - Android User Interface

Android examples for User Interface:Key Event

Description

Convenience method for setting the ripple hotspot during an onTouch event for Lollipop+ devices

Demo Code


//package com.java2s;

import android.graphics.drawable.Drawable;
import android.os.Build;

import android.view.MotionEvent;
import android.view.View;

public class Main {
    /**//from  w  w  w  . jav  a2  s  .  c o  m
     * Convenience method for setting the ripple hotspot during an onTouch event for Lollipop+ devices
     *
     * @param view  The input view
     * @param event The MotionEvent object from onTouch method
     */
    public static void setTouchEventHotSpot(View view, MotionEvent event) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Drawable background = view.getBackground();
            if (background != null) {
                background.setHotspot(event.getX(), event.getY());
            }
        }
    }
}

Related Tutorials