1

I want imageview to become brighter when an user presses (clicks) it, but without an additional image for that state. Is it possible? We know we have selectors where 2 different images can be used, but I would like to have a selector, a drawable from XML, and one real image.

Yar
  • 4,543
  • 2
  • 35
  • 42

2 Answers2

0
Bitmap bitmap;
Drawable drawableBitmap= new BitmapDrawable(bitmap);
drawableBitmap.SetAlpha(--change here--);

convert image to drawable. set alpha.

samuelesque
  • 1,165
  • 13
  • 30
0

OK, I got it working. Add

implements OnTouchListener

to the definition of your activity, add

.setOnTouchListener(this);

to all your imageviews that must respond to click with getting brighter, and add:

@Override
public boolean onTouch(View pV, MotionEvent pEvent) {
    if(pEvent.getAction() == MotionEvent.ACTION_DOWN){
        ((ImageView)pV).setAlpha(128);
    }
    else if(pEvent.getAction() == MotionEvent.ACTION_UP){
        ((ImageView)pV).setAlpha(255);
    }
    return true;
}    

to your activity. That's all.

Yar
  • 4,543
  • 2
  • 35
  • 42
  • 1
    This doesn't appear to work with bitmap drawables. See @dotsamuelswan answer and: http://stackoverflow.com/questions/5118894/set-alpha-of-bitmap-image – greg7gkb Jul 12 '13 at 23:58