Tuesday, January 7, 2014

How to set image button click effect ?

I have one simple solution using that you can set default press effect to button.

// Create button and add event
Button addImageView = (Button) bottomView.findViewById(R.id.addImage);
addImageView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// click event
}
});


//Using this code set touch listener

addImageView.setOnTouchListener(touchEffect);

//touch listner
OnTouchListener touchEffect = new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    v.getBackground().setColorFilter(0xe0f47521,PorterDuff.Mode.SRC_ATOP);
                    v.invalidate();
                    break;
                }
                case MotionEvent.ACTION_UP: {
                    v.getBackground().clearColorFilter();
                    v.invalidate();
                    break;
                }
            }
            return false;
        }

    };

10 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.
    Data Science training in Chennai | Data science training in bangalore
    Data science training in pune| Data science online training
    Pyton training in Kalyan nagar

    ReplyDelete
  3. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune

    ReplyDelete

  4. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.


    Amazon Web Services Training in Velachery, Chennai |AWS Training in Velachery , Besant Technologies

    Amazon Web Services Training in Chennai | AWS Training in Chennai

    Amazon Web Services Training in Chennai |Best AWS Training in Chennai

    Amazon Web Services Training in Chennai | AWS Training in OMR,Chennai

    ReplyDelete
  5. Your content is nothing short of brilliant in many ways. I think this is engaging and eye-opening material. Thank you so much for caring about your content and your readers.
    data analytics courses in hyderabad

    ReplyDelete

content -->