机器人添加半透明不同颜色的边框和阴影效果,图像边框、机器人、不同颜色、阴影

2023-09-03 22:57:23 作者:忘却

其效果如下所示:

请注意:

从原始图像1.边框的颜色各不相同,你可以看到Gmail的图标边框边框是黑色,其他图标是白色的。边框的颜色是从原始图像

2,图像有阴影

和如何实现点击的影响?

解决方案

而不是使用setOnClickListner使用setOnTouchListener取得预期的效果

  

((按钮)findViewById(R.id.testBth))。setOnTouchListener(新   OnTouchListener(){

  @覆盖
        公共布尔onTouch(视图V,MotionEvent事件){
          开关(event.getAction()){
          案例MotionEvent.ACTION_DOWN:{
              按钮来查看=(按钮)V;
              view.getBackground()setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP)。
              v.invalidate();
              打破;
          }
          案例MotionEvent.ACTION_UP:
              //你的行动在这里按一下按钮
          案例MotionEvent.ACTION_CANCEL:{
              按钮来查看=(按钮)V;
              。view.getBackground()clearColorFilter();
              view.invalidate();
              打破;
          }
          }
          返回true;
        }
    });
 
PS图片上的字怎么加不同颜色的边框,不同颜色的填充

The effect is looks like this:

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 ?

解决方案

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;
        }
    });