florent37/ViewTooltip

Is there any way to auto close the tooltip when navigating away from the fragment in the same activity?

Opened this issue · 4 comments

Is there any way to auto close the tooltip when navigating away from the fragment in the same activity?

I added the following to the ViewTooltip class.

public class ViewTooltip {
    private static ArrayList<TooltipView> allToolTips = new ArrayList<>();
    public static void hideAllVisibleToolTips() {
        for (TooltipView tip: allToolTips) {
            tip.removeNow();
        }
    }

then in the Tooltip constructor I added (right above setWithShadow(true);)

**allToolTips.add(TooltipView.this);**
You can then call this function ViewTooltip.hideAllVisibleToolTips() when navigating away from your fragment.

It works well for me.

Nice! In which version will this be available?

I am currently using 1.1.5 and I solved it in a dirty way by saving the instance of tooltip as a member variable in Fragment instead of local. So that on certain events I can check if it's not null and call closeNow on it.

I didnt have any plans to push the change. Someone is welcome to if they'd like.

What I wrote above is really everything that's needed to make it work.

Whenever I load a new fragment I just call

ViewTooltip.hideAllVisibleTooltips()

In my code and they get removed.

If you set tooltip on rootView like this, it'll hide automatically when parent view is not visible.
ViewTooltip.on(context, relView, imgDot)...