亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在旋轉時更改 AppCompatButton 的背景?

如何在旋轉時更改 AppCompatButton 的背景?

繁花如伊 2023-05-10 17:09:07
我正在使用 RotateAnimation 旋轉 AppCompatButton,用作工具欄按鈕,我想在旋轉時更改其背景。到目前為止,我沒有找到任何有用的主題。這是我的代碼:AppCompatButton mBtn = (AppCompatButton) view.findViewById(R.id.search_btn);         Animation mRotateAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotation); mBtn.setAnimation(mRotateAnimation); mBtn.startAnimation(mRotateAnimation);旋轉.xml:<rotate     xmlns:android="http://schemas.android.com/apk/res/android"     android:fromDegrees="0"     android:toDegrees="360"     android:pivotX="50%"     android:pivotY="50%"     android:repeatCount="0"     android:duration="600" />我想在動畫的開始和結束之間獲得平滑的背景變化。任何有用的資源鏈接或代碼都會很棒。感謝你們!
查看完整描述

1 回答

?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

您應該ValueAnimation在視圖中添加另一個。


AppCompatButton mBtn = (AppCompatButton) view.findViewById(R.id.search_btn);

        Animation mRotateAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotation);

mBtn.setAnimation(mRotateAnimation);

mBtn.startAnimation(mRotateAnimation);


int colorFrom = getResources().getColor(R.color.red);

int colorTo = getResources().getColor(R.color.blue);

ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);

colorAnimation.setDuration(600);

colorAnimation.addUpdateListener(new AnimatorUpdateListener() {


    @Override

    public void onAnimationUpdate(ValueAnimator animator) {

        mBtn.setBackgroundColor((int) animator.getAnimatedValue());

    }


});

colorAnimation.start();


查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號