MaterialShowcaseView icon indicating copy to clipboard operation
MaterialShowcaseView copied to clipboard

Not able to target showcase on actionbar item

Open goswamiji0 opened this issue 8 years ago • 7 comments

I am facing issues that I want to target the showcase on action bar item but don't know how it is done

goswamiji0 avatar Sep 22 '17 13:09 goswamiji0

ShowcaseConfig config = new ShowcaseConfig();

MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, UNIQUE_ID);

sequence.setConfig(config);

sequence.addSequenceItem(findViewById(R.id.action_search), "This is menu one", "GOT IT");

sequence.addSequenceItem(findViewById(R.id.action_add), "This is menu two", "GOT IT");

sequence.start(); This worked for me. Add this in onCreateOptionsMenu after inflating the menu and use menu id to find the view.

vishnusp avatar Dec 16 '17 07:12 vishnusp

I use this Kotlin static function to get the view in a toolbar (works for action and menu items)

/**
 id is the itemId, as set in menu.add() or XML id tag (R.id.action_add)
*/
fun getToolbarViewContainingMenuItem(toolbar: Toolbar, id: Int): View? {
        for (i in 0 until toolbar.childCount) {
            if (toolbar.getChildAt(i) is ActionMenuView) {
                val menuView = toolbar.getChildAt(i) as ActionMenuView

                for(childIndex in 0 until menuView.childCount) {

                    if(childIndex >= (menuView.childCount - 1)) return menuView.getChildAt(menuView.childCount - 1)

                    val child = menuView.getChildAt(childIndex) as? ActionMenuItemView ?: continue

                    if( child.id == id ) return child
                }

            }
        }
        return null
    }

btraas avatar Mar 23 '18 22:03 btraas

I had same problem and I was struggling with it for couple of days.Finally I got a clue from another library and just did it here and it was just calling toolbar.inflateMenu(menuid) in onCreate() just like this: protected void onCreate(){ ... toolbar = findViewById(R.id.my_toolbar_layout); toolbar.inflateMenu(R.menu.item_list_activity_menu); setSupportActionBar(toolbar); ... }

ali73 avatar Jun 20 '18 06:06 ali73

how to use this functionality in fragment. i'm trying to implement it but not able to complete

kumar5572 avatar Aug 26 '19 11:08 kumar5572

For fragment, this worked for me:

(activity as MainActivity).toolbar[1] returns the view for menu (3 dots). Index 0 returns view for Toolbar title.

murdak avatar Jan 14 '22 02:01 murdak

ShowcaseConfig config = new ShowcaseConfig();

MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, UNIQUE_ID);

sequence.setConfig(config);

sequence.addSequenceItem(findViewById(R.id.action_search), "This is menu one", "GOT IT");

sequence.addSequenceItem(findViewById(R.id.action_add), "This is menu two", "GOT IT");

sequence.start(); This worked for me. Add this in onCreateOptionsMenu after inflating the menu and use menu id to find the view.

Doesn't work as findViewById returns null.

murdak avatar Jan 14 '22 02:01 murdak

For fragment, this worked for me:

(activity as MainActivity).toolbar[1] returns the view for menu (3 dots). Index 0 returns view for Toolbar title.

That's the only working way for fragments, thank you!!!

DonMarv00 avatar Dec 21 '22 19:12 DonMarv00