MaterialShowcaseView icon indicating copy to clipboard operation
MaterialShowcaseView copied to clipboard

Add action item as a target

Open cardovaeric opened this issue 10 years ago • 15 comments

hi, how can i add action item in the Action Bar (e.g home button, settings) as a target? thank you

cardovaeric avatar Sep 03 '15 14:09 cardovaeric

activity.findViewById(R.id.action_item) should work after menu is created in onCreateOptionsMenu()

ntoskrnl avatar Sep 03 '15 15:09 ntoskrnl

While my pull request is awaiting review, you can check out my fork of this library (there is example with action item and it also supports custom padding, rectangle shape) :)

ntoskrnl avatar Sep 03 '15 15:09 ntoskrnl

@ntoskrnl thank you for your fast response i tried sample sequence activity and i add the menu item at onCreateOptionsMenu() like you said

http://codepad.org/9XtTOnUU

but it got nullpointer exception...

cardovaeric avatar Sep 03 '15 16:09 cardovaeric

You should show the viewcase only if the activity has already drawn all it's views. A good point for showing it would be your activity's onResume...

MFlisar avatar Sep 03 '15 16:09 MFlisar

@MFlisar thank you for your response. i called it in onResume and still got error i end up with calling it with postDelayed method at onCreate with 500ms delay and it worked! i already checked the logcat, onResume method called when activity still not drawn all its views.

this is my final code Handler myHandler = new Handler(); myHandler.postDelayed(new Runnable() { @Override public void run() { showMaterialShowCase(); } }, 500);

cardovaeric avatar Sep 04 '15 04:09 cardovaeric

Another good way that is not hoping for good timing is following:

Post a method on a view directly or add a GlobalLayoutObserver and remove it after the first call...

I use the view.post(...) method and had never a crash based on that yet...

MFlisar avatar Sep 04 '15 04:09 MFlisar

Hi it does not work with the new toolbar

huteri avatar Nov 03 '15 04:11 huteri

@huteri it does work, in my project i use the new toolbar

cardovaeric avatar Nov 03 '15 07:11 cardovaeric

@cardovaeric I could not make it work with activity.findViewByid() in onCreateOptionsMenu, but it does work with Toolbar.findViewById()

huteri avatar Nov 03 '15 08:11 huteri

This worked for me

if(getActivity().findViewById(R.id.menu_item)!=null) sequence.addSequenceItem(getActivity().findViewById(R.id.menu_item), "Description", "GOT IT");

balavishnu avatar Nov 09 '15 17:11 balavishnu

The answer here works for me.

croespino avatar Mar 02 '16 06:03 croespino

thank you very much @balavishnu and @cardovaeric this work for me if(getActivity().findViewById(R.id.menu_item)!=null) sequence.addSequenceItem(getActivity().findViewById(R.id.menu_item), "Description", "GOT IT");

AND

Handler myHandler = new Handler(); myHandler.postDelayed(new Runnable() { @Override public void run() { showMaterialShowCase(); } }, 500);

rasik1010 avatar Oct 03 '16 14:10 rasik1010

I found a better solution with

OnCreate:

  toolbar.post(new Runnable() {
        @Override
        public void run() {
            showMaterialShowCase();
        }
    });

AndersonCotrim avatar Mar 19 '18 20:03 AndersonCotrim

How can we put SKIP button same like GOT IT button in ShowcaseView so that we can skip rest introduction showcaseViw ? any one know? please help me if any one know thanks...

rasik1010 avatar Mar 20 '18 05:03 rasik1010

I found a better solution with

OnCreate:

  toolbar.post(new Runnable() {
        @Override
        public void run() {
            showMaterialShowCase();
        }
    });

Thank you this worked for me. I was using toolbar menu with animated Lottie files as each item. This worked for me just fine

codeaskush avatar May 22 '20 08:05 codeaskush