我向我的 fab 按鈕添加了圓形顯示動畫,但我不想將片段顏色更改為不同的顏色,而是想更改動畫的顏色,因為我希望我的下一個片段是白色背景。我試圖將片段顏色更改為不同于白色并再次變回白色,但它沒有用。那么有沒有辦法改變動畫的顏色,而不是片段的顏色?這是我的一些代碼:@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment final View rootView = inflater.inflate(R.layout.fragment_note_add, container, false); rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener(){ @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom){ rootView.removeOnLayoutChangeListener(this); rootView.setBackgroundColor(getArguments().getInt("color")); int cx = getArguments().getInt("cx"); int cy = getArguments().getInt("cy"); int radius = (int) Math.hypot(right, bottom); Animator reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius); reveal.setInterpolator(new DecelerateInterpolator(2f)); reveal.start(); } }); return rootView; }在這里,我再次嘗試將背景設為白色。 @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { //Initialize UI Elements FloatingActionButton saveButton = view.findViewById(R.id.fab_add); saveButton.setOnClickListener(saveButtonListener); editText = view.findViewById(R.id.note_editor); view.setBackgroundColor(getResources().getColor(R.color.white)); super.onViewCreated(view, savedInstanceState); }
1 回答

動漫人物
TA貢獻1815條經驗 獲得超10個贊
在這種情況下沒有“動畫顏色”這樣的東西。Circular Reveal 動畫,在引擎蓋下,將圓形裁剪蒙版應用于視圖并為裁剪值設置動畫以在視覺上表示“顯示”。您看到的顯示顏色是實際視圖本身。
如果我理解正確,您希望在顯示運行時在您的視圖中進行顏色轉換。如果是這種情況,請遵循以下步驟:
聲明開始和結束顏色。
將動畫偵聽器附加到圓形顯示動畫。
在顯示動畫更新時,使用 ARGBevaluator 使用顯示動畫當前進度在開始和結束顏色之間進行評估。將此顏色值設置為視圖的背景。
添加回答
舉報
0/150
提交
取消