0

The effect is looks like this: border and shadow

please note:

1.The border's color vary from the original image, you can see the Gmail icon border border is black and the other icon is white. The border's color is from the original image.

2.The image have shadow

And how to implement the clicked effect ?

clicked effect

Jonguo
  • 681
  • 1
  • 10
  • 17

1 Answers1

1

Rather than using setOnClickListner use setOnTouchListener to gain the desired effect

((Button)findViewById(R.id.testBth)).setOnTouchListener(new OnTouchListener() {

      @Override
        public boolean onTouch(View v, MotionEvent event) {
          switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN: {
              Button view = (Button) v;
              view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
              v.invalidate();
              break;
          }
          case MotionEvent.ACTION_UP:
              // Your action here on button click
          case MotionEvent.ACTION_CANCEL: {
              Button view = (Button) v;
              view.getBackground().clearColorFilter();
              view.invalidate();
              break;
          }
          }
          return true;
        }
    });
Vinayak Bevinakatti
  • 40,205
  • 25
  • 108
  • 139
  • Thank you ,it works for the clicked effect, but how to add border and shadow? hope you can help me . – Jonguo May 13 '14 at 10:17
  • For shadow try this http://stackoverflow.com/a/15333577/28557 and for border you can convert you drawable to bitmap and you can fix boder to it. Also check http://stackoverflow.com/questions/3263611/border-for-an-image-view-in-android – Vinayak Bevinakatti May 13 '14 at 10:29
  • I tried it, I have to put the effect all together. Thank you! It takes some time to implement it. – Jonguo May 13 '14 at 11:52
  • still don't know how to do it. – Jonguo May 13 '14 at 12:34
  • ok, I soled by myself , thank you. This is the demo project.https://github.com/com314159/LauncherIconMaskEffect – Jonguo May 16 '14 at 12:52