我向我的 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);
}