rainer
rainer

Reputation: 3411

Codename One Drag and Drop - Target change background color on Drag Over

I have an Android application with some draggable elements.

There are some some labels that I want do drag over containers. The moment I drag over the container, I want the container background to change its colour.

I am unable to achieve this with DragOverListener from the API.

This is my code:

 label.addDragOverListener(l -> {
        container.getAllStyles().setBgColor(ColorUtil.YELLOW);
        container.getAllStyles().setBgTransparency(255);
});

What happens is that as soon as I start dragging the label, the container changes the colour. But that's not what I want. I want the container to change the colour only when I drag over it.

Is there a way to achieve this?

Many thanks in advance.

Upvotes: 1

Views: 91

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

The event delivers an X/Y location for the drag which you can use to determine whether to draw the color or not. Generally, this API is designed for refined drawing of this type e.g. drawing a square in the place the dropped component will occupy.

Upvotes: 1

Related Questions