0

I have a button. I want to simulate a click on. performClick() does most of the job, but it doesn't do the button's animation. I tried setPressed and setEnabled as well, but no dice.

2 Answers 2

7

Call invalidate after the setPressed to force the view to redraw:

btn.setPressed(true);
btn.invalidate();
Sign up to request clarification or add additional context in comments.

3 Comments

Yep, does what I want it to--but now how do I reset it? It gets stuck in the second drawable state, and neither invalidate() a second time nor setPressed(false) seems to bring it back.
You must set it to false and then invalidate again: btn.setPressed(false); btn.invalidate();
Thanks a bunch! What I was doing wrong was putting it in the wrong place--I had to put the setpressed(false) in the ACTION_UP case, or else it executed everything to fast and you couldn't see the button change.
0

Try to use tool Monkey.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.