0

I recently added toolbar in my project by manually setting it by setSupportActionbar(toolbar). Right now I am facing an issue like I can't get view reference to media router button in toolbar, so showcase view not working. Is there any work around for showing showcase view in media route button?

My menu set is as follows:

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/search"
        android:orderInCategory="200"
        android:title="@string/text_search"
        android:menuCategory="system"
        app:actionViewClass="android.support.v7.widget.SearchView"
        app:showAsAction="always" />

    <item
        android:id="@+id/media_route_menu_item"
        android:orderInCategory="100"
        android:title="@string/media_route_menu_title"
        app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
        app:showAsAction="always" />
    <item
        android:id="@+id/downloads"
        android:orderInCategory="90"
        android:icon="@drawable/ic_actionbar_download"
        android:visible="false"
        app:showAsAction="ifRoom"
        android:title="Downloads"/>
    <item
        android:id="@+id/cancel"
        android:title="Cancel"
        android:visible="false"
        app:showAsAction="never"/>


</menu>
vard
  • 4,057
  • 2
  • 26
  • 46

3 Answers3

1

You can try this code it works for me

    Target viewTarget = new Target() {
    @Override
    public Point getPoint() {
        return new ViewTarget(toolbar.findViewById(R.id.media_route_menu_item)).getPoint();
    }
};

sv = new ShowcaseView.Builder(this)
        .setTarget(viewTarget)
        .singleShot(2)
        .setShowcaseEventListener(this)
        .build();
Wasim K. Memon
  • 5,979
  • 4
  • 40
  • 55
0

You an get a pointer to the "view" directly:

    Menu menu = mToolbar.getMenu();
    View view = menu.findItem(R.id.media_route_menu_item).getActionView();
    if (view != null && view instanceof MediaRouteButton) {
        new ShowcaseView.Builder(this)
                .setTarget(new ViewTarget(view))
                .setContentTitle(R.string.touch_to_cast)
                .build();
    }

If you were using CCL, you would get this functionality without a need to bring in the Showcase library.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • 2
    Right now I am getting null pointer exception on getActionView() called on an null object. I debugged it the problem is the toolbar returned menu didn't contain any items. – Sayooj O Feb 09 '16 at 20:53
  • Can you post the code you use to set the menu on the toolbar? – Alex Curran Feb 09 '16 at 21:09
  • @alex : I am inflating menu in my onCreateOptionMenu() callback – Sayooj O Feb 09 '16 at 21:11
  • Are you setting this toolbar as the action bar by using the `setSupportActionBar()` method? That is required to use `onCreateOptionsMenu()` with a toolbar. – Alex Curran Feb 09 '16 at 21:18
  • @alex : Is there any way i can get view reference to my toolbar menu item ? In above suggestion the menu returned by toolbar itself have no items in it – Sayooj O Feb 09 '16 at 21:23
  • You might want to post your full activity code for folks to see what you are doing. It can be a matter of timing as well, is your menu inflated by the time you are trying to find the menu item? – Ali Naddaf Feb 09 '16 at 22:18
0
custom ShowcaseView : 

- First Initialize ShowcaseConfig Object :
  ShowcaseConfig config = new ShowcaseConfig();

- If your Set Custome Text :
        config.setTypeface(tf); 

- set delay between two view
        config.setDelay(500); // half second between each showcase view

- set Content Text and Button Size :
        if (Util.isZhCN()) {
            config.setContentTextSize(24);
            config.setButtonTextSize(22);
        } else {
            config.setContentTextSize(36);
            config.setButtonTextSize(30);
        }


        MaterialShowcaseSequence sequence = new 
  MaterialShowcaseSequence(context, "sequence example");

        sequence.setConfig(config);

        MaterialShowcaseView oneShowcaseView = new MaterialShowcaseView.Builder(context)
                .setTarget(" PUT YOUR TARGEXT VIEW").setContentText(" PUT YOUR CONTENT").build();

        sequence.addSequenceItem(oneShowcaseView);
        sequence.start();


- try this work for me.
Jaydeep Dobariya
  • 465
  • 6
  • 12