ImageView :
ImageView imgView= (ImageView) findViewById(R.id.color_blue); imgView.setDrawingCacheEnabled(true); imgView.setOnTouchListener(changeColorListener);
OnTouchListener:
private final OnTouchListener changeColorListener = new OnTouchListener() { @Override public boolean onTouch(final View v, MotionEvent event) { Bitmap bmp = Bitmap.createBitmap(v.getDrawingCache()); int color = 0; try { color = bmp.getPixel((int) event.getX(), (int) event.getY()); } catch (Exception e) { // e.printStackTrace(); } if (color == Color.TRANSPARENT) return false; else { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //do something here break; case MotionEvent.ACTION_OUTSIDE: break; case MotionEvent.ACTION_CANCEL: break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_SCROLL: break; case MotionEvent.ACTION_UP: //do something here break; default: break; } return true; } } };
Thanx. this post solved my problem!!
ReplyDeleteMost welcome!
DeleteThis comment has been removed by the author.
ReplyDeleteThank You! I implemented this for custom Button =)
ReplyDelete:-) Most welcome!
DeleteWhy do I get NullPointer? :/
ReplyDeleteUpdated the post. :)
DeleteThank you!!
ReplyDeleteMy pleasure :-)
DeleteI need to make the Transparent region clickable (png image frame)
ReplyDelete