滄海一幻覺(jué)
2023-06-08 20:57:58
我向我的 fab 按鈕添加了圓形顯示動(dòng)畫(huà),但我不想將片段顏色更改為不同的顏色,而是想更改動(dòng)畫(huà)的顏色,因?yàn)槲蚁M业南乱粋€(gè)片段是白色背景。我試圖將片段顏色更改為不同于白色并再次變回白色,但它沒(méi)有用。那么有沒(méi)有辦法改變動(dòng)畫(huà)的顏色,而不是片段的顏色?這是我的一些代碼:@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; }在這里,我再次嘗試將背景設(shè)為白色。 @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 回答

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