Emanuel Graf
Emanuel Graf

Reputation: 766

Change a button background while its background is in an animation?

My button is animated like this:

AnimationDrawable animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.startmain), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.startmainan), 1000);

animation.setOneShot(false);

Button imageAnim = (Button) findViewById(R.id.btn_start);
imageAnim.setBackgroundDrawable(animation);

// start the animation!
animation.start();

but I want to change its background again when an user presses on it, like in the xml of the background:

<item android:drawable="@drawable/kp_p" android:state_pressed= "true" />
<item android:drawable="@drawable/kp" />

but these 2 things won't work together this way, only the animation is doing its work. How can I bring these 2 things together to work?

Upvotes: 2

Views: 350

Answers (1)

gkondati
gkondati

Reputation: 526

Instead adding background from XML file, add programmatically.

Upvotes: 1

Related Questions