worker8 / TourGuide

TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View
MIT License
2.63k stars 416 forks source link

Overlay is not Visible in Fragment #104

Open javiyavandan opened 7 years ago

javiyavandan commented 7 years ago

I am using tooltip library to show Guide tour in my app. My Whole app works with fragments. On right side of action bar i have button which opens Drawer menu . I want to show tooltip options in my Fragment . Here is a code which i have used to show tooltip.

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (rootView != null) {
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (parent != null) {
                parent.removeView(rootView);
            }
        } 
else 
{
            if (rootView == null) {
                rootView = inflater.inflate(R.layout.fragment_networks, container, false);

        mSearchEditText = (EditText) rootView.findViewById(R.id.et_search_fragment_networks);

      TourGuide mTourGuideHandler = TourGuide.init(getActivity()).
                        with(TourGuide.Technique.Click).setPointer(new Pointer()).setToolTip(new ToolTip().setTitle("Welcome!")
                        .setDescription("Click on Get Started to begin...")).setOverlay(new Overlay(true,R.color.red, Overlay.Style.Rectangle)).playOn(mSearchEditText);

            }
        }
        return rootView;
    }

When i run app i can't see any overlay on screen . But i can see tooltip on perfect position . Can you help me to solve this issue ? I can see Overlay in Kitkat but i can't see overlay in Lolipop and above versions. Thanks

acorn371 commented 6 years ago

I had a similar problem. I think mSearchEditText isn't layed out yet, inside onCreateView method and TourGuide can't compute EditText size and position well. Try something like:

mSearchEditText = (EditText) rootView.findViewById(R.id.et_search_fragment_networks);

mSearchEditText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    public void onGlobalLayout() {
        if (Build.VERSION.SDK_INT < 16)
            mSearchEditText.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        else
            mSearchEditText.getViewTreeObserver().removeOnGlobalLayoutListener(this);

    TourGuide mTourGuideHandler = TourGuide.init(getActivity()).with(TourGuide.Technique.Click)
        .setPointer(new Pointer())
        .setToolTip(new ToolTip().setTitle("Welcome!")
                            .setDescription("Click on Get Started to begin..."))
        .setOverlay(new Overlay(true,R.color.red, Overlay.Style.Rectangle))
        .playOn(mSearchEditText);
    }
});