Skip to content

Instantly share code, notes, and snippets.

@alorma
Created May 13, 2015 10:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorma/52e5f733ae99dd687b71 to your computer and use it in GitHub Desktop.
Save alorma/52e5f733ae99dd687b71 to your computer and use it in GitHub Desktop.
package com.worldline.evasdk.view.utils;
import android.support.v4.view.ViewCompat;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by a557114 on 07/05/2015.
*/
public class ElevationUtils {
public static void addTouchElevation(final View itemView) {
final int elevationDefault = (int) ViewCompat.getElevation(itemView);
if (elevationDefault > 0) {
final int elevationSelected = elevationDefault * 2;
itemView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
ViewCompat.setElevation(itemView, elevationSelected);
} else {
if (ViewCompat.getElevation(itemView) != elevationDefault) {
ViewCompat.setElevation(itemView, elevationDefault);
}
}
}
return false;
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment