在背景处于动画状态时更改按钮背景?

时间:2015-04-23 19:34:19

标签: java android xml animation

我的按钮动画如下:

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();

但我希望在用户按下它时再次更改其背景,例如在后台的xml中:

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

但是这两件事情不会以这种方式一起工作,只有动画才能正常工作。我怎样才能把这两件事放在一起工作?

1 个答案:

答案 0 :(得分:1)

而是从XML文件添加背景,以编程方式添加。

相关问题