在我的应用程序中,我有一个textview,当用户拖动另一个项目时,我想在其背景上放置一个颜色过滤器。在我的DragListener中,我使用以下代码但是colorfilter没有生效:
case DragEvent.ACTION_DRAG_ENTERED:
v.getBackground().setColorFilter(Color.BLUE, PorterDuff.Mode.LIGHTEN);
当我在MainActivity中输入相同的代码而不是DragLlistener时,它可以正常工作,如下所示:
findViewById(R.id.textView2).getBackground().setColorFilter(Color.BLUE, PorterDuff.Mode.LIGHTEN)
同样在DragListener中当我将背景颜色更改为其他颜色时,colorfilter生效,当我将其更改回我想要的颜色时,colorfilter保持有效。 clearColorFilter也是如此(为了使它生效我必须改变背景颜色)。 这就是我所说的:
case DragEvent.ACTION_DRAG_ENTERED:
v.getBackground().setColorFilter(Color.BLUE, PorterDuff.Mode.LIGHTEN);
v.setBackgroundColor(Color.BLACK);
v.setBackgroundColor(con.getResources().getColor(R.color.background));
我的问题是为什么我必须将背景颜色设置为不同的颜色过滤器才能在DragListener中生效,而不是在MainActivity中生效?我错过了什么吗?