3
클릭하면 두 개의 배경색을 앞뒤로 전환하여 번 깜박이는 버튼을 표시하고 싶습니다.Android, 애니메이션으로 버튼 배경색을 설정 하시겠습니까?
This 대답은 깜박이는 버튼을 만들기 위해 AlphaAnimation
을 사용
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
final Button btn = (Button) findViewById(R.id.your_btn);
btn.startAnimation(animation);
을하지만 난 그게 배경색으로 작동시킬 수 없습니다.
안드로이드 Studio는 다음을 자동으로 완료되지 않습니다 :
animation = new Animation() {
@Override
public void setBackgroundColor(int bg) {
super.setBackgroundColor(bg);
}
};
하지만 (bg = Color.parseColor("#ffff9434")
와) 버튼에 적용하려하지만 주사위.
미리 감사드립니다.
편집 또한 다음을 시도했지만이되지 않으며 대답을 참조
Button btn = (Button)this.findViewById(R.id.btn1);
//Let's change background's color from blue to red.
ColorDrawable[] color = {new ColorDrawable(Color.BLUE), new ColorDrawable(Color.RED)};
TransitionDrawable trans = new TransitionDrawable(color);
//This will work also on old devices. The latest API says you have to use setBackground instead.
btn.setBackgroundDrawable(trans);
trans.startTransition(5000);
ETID 2
가 작동있어 (here에서) 작동하지 않았다
아래
솔루션을 찾고 답변을 게시했지만 다른 사람들이 3 대신 4 가지 솔루션을 제공하도록 남겨 두겠습니다. – Birrel
좋습니다. 선생님, 잘 ....... – Elltz