Amir
Amir

Reputation: 16607

First launch Tutorial in android - Show case view with fragment

After searching a lot I found a nice repository on Github which show something that i want , but the problem is I use fragments in my app and i don't know how to use library ! in my first attemp it gives me following Error

 "java.lang.IllegalArgumentException: width and height must be > 0"

I found a solution HERE but now it doesn't show something.( in fact demo screen doesn't show up ) can any give a piece of code which works fine with fragment ? or help me how to solve this ?

Thanks.

Upvotes: 0

Views: 1952

Answers (1)

zaPlayer
zaPlayer

Reputation: 862

hey man just made a sample here for you

i literally done nothing just used the library inside the onCreateView and it worked

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        new ShowcaseView.Builder(getActivity())
                .setTarget(new ActionViewTarget(getActivity(), ActionViewTarget.Type.HOME))
                .setContentTitle("ShowcaseView")
                .setContentText("This is highlighting the Home button")
                .hideOnTouchOutside()
                .build();
        return rootView;
    }

Update for the question in the comment

just add your code on the onActivityCreated method check the sample created

public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (savedInstanceState==null){
            View view = getActivity().findViewById(R.id.hometxv);
            view.post(new Runnable() {
                @Override
                public void run() {
                    if (isAdded()) {
                        ShowcaseView sv;
                        ViewTarget target=new ViewTarget(R.id.hometxv,getActivity());
                        RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                        lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                        int margin = ((Number) (getResources().getDisplayMetrics().density * 12)).intValue();
                        lps.setMargins(margin, margin, margin, margin);

                        sv = new ShowcaseView.Builder(getActivity(), true)
                                .setTarget(target)
                                .setContentTitle("hold up")
                                .setContentText("smoke weed everyday")
                                .setShowcaseEventListener(new OnShowcaseEventListener() {
                                    @Override
                                    public void onShowcaseViewHide(ShowcaseView showcaseView) {

                                    }

                                    @Override
                                    public void onShowcaseViewDidHide(ShowcaseView showcaseView) {

                                    }

                                    @Override
                                    public void onShowcaseViewShow(ShowcaseView showcaseView) {

                                    }
                                })
                                .build();
                        sv.setButtonPosition(lps);
                    }
                }
            });
        }
    }

enjoy :D

Upvotes: 1

Related Questions