Search code examples
androidonclickimageviewglow

how to hide glow effect?


Glow effect is working fine. my doubt is how to hide glow effect? if i click my imageview, that time only i wish to show my glow effect please how to hide and show glow effect while on click.

code:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // An added margin to the initial image
        int margin = 24;
        int halfMargin = margin / 2;

        // the glow radius
        int glowRadius = 16;

        // the glow color
        int glowColor = Color.rgb(0, 192, 255);

        // The original image to use
        Bitmap src = BitmapFactory.decodeResource(getResources(),
                R.drawable.test);

        // extract the alpha from the source image
        Bitmap alpha = src.extractAlpha();

        // The output bitmap (with the icon + glow)
        Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
                src.getHeight() + margin, Bitmap.Config.ARGB_8888);

        // The canvas to paint on the image
        Canvas canvas = new Canvas(bmp);

        Paint paint = new Paint();
        paint.setColor(glowColor);

        // outer glow
        paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
        canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

        // original icon
        canvas.drawBitmap(src, halfMargin, halfMargin, null);
        setContentView(R.layout.activity_main);

        ((ImageView) findViewById(R.id.bmpImg)).setImageBitmap(bmp);

    }
}

present screen shot:

enter image description here


Solution

  • set onclicklistener and implement this code:

    .setOnClickListener(clicklistener);
    
    
    private OnClickListener backListener = new OnClickListener() {
            public void onClick(View v) {
        // An added margin to the initial image
            int margin = 24;
            int halfMargin = margin / 2;
    
            // the glow radius
            int glowRadius = 16;
    
            // the glow color
            int glowColor = Color.rgb(0, 192, 255);
    
            // The original image to use
            Bitmap src = BitmapFactory.decodeResource(getResources(),
                    R.drawable.test);
    
            // extract the alpha from the source image
            Bitmap alpha = src.extractAlpha();
    
            // The output bitmap (with the icon + glow)
            Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
                    src.getHeight() + margin, Bitmap.Config.ARGB_8888);
    
            // The canvas to paint on the image
            Canvas canvas = new Canvas(bmp);
    
            Paint paint = new Paint();
            paint.setColor(glowColor);
    
            // outer glow
            paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
            canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);
    
            // original icon
            canvas.drawBitmap(src, halfMargin, halfMargin, null);
    }}