Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request:- Expose method which takes menuitem as target #72

Closed
squarenotch opened this issue Nov 20, 2016 · 10 comments
Closed

Feature Request:- Expose method which takes menuitem as target #72

squarenotch opened this issue Nov 20, 2016 · 10 comments

Comments

@squarenotch
Copy link

I have a situation where I change the visibility of a menuitem in onPrepareOptionsMenu within a fragment. I want to show a TapTargetView when the item becomes visible.

I have a reference to the menuitem and would like to create the TapTargetView with the menuitem as the target, possibly in onPrepareOptionsMenu.

I have tried getting a reference to the toolbar and finding the item in onPrepareOptionsMenu using the id but it always resolves as null in this method.

Could you assist or possibly add the ability to pass a menuitem?

Thanks
Jason

@xiphirx
Copy link
Collaborator

xiphirx commented Nov 20, 2016

Have you tried targeting MenuITem.getActionView() ?

@squarenotch
Copy link
Author

squarenotch commented Nov 20, 2016

@xiphirx Yes with TapTarget.forView, in onPrepareOptionsMenu, this method returns null. Possibly because it has just been inflated?

@xiphirx
Copy link
Collaborator

xiphirx commented Nov 20, 2016

TapTarget.forToolbarMenuItem(...) Should work fine. Are you sure you're setting an ID for the item and that it exists at the time you're trying to target it?

@squarenotch
Copy link
Author

The menu is inflated in CreateOptionsMenu and after some changes to the items I am calling TapTarget.forToolbarMenuItem(toolbar, R.id.menu_mymenuitem.... etc) - This always resolves to null.

I took a look at the toolbar variable and although the MenuItem is in the mItems collection, it is not in the mActionItems collection. I am guessing but its either because it has been added by the fragment or that the item is not fully added to the toolbar in the onPrepareOptionsMenu method?

You see my reason for simply being able to supply a menuitem object :) (banging head on wall)

@xiphirx
Copy link
Collaborator

xiphirx commented Nov 21, 2016

Supplying a MenuItem does the library no good if getActionView is returning null. The library currently requires a view to target.

Could you possible provide a minimal code sample that would replicate this? I can take a further look afterwards

@squarenotch
Copy link
Author

` @OverRide
public void onPrepareOptionsMenu(Menu menu) {

    mShowSubscribedOnlyMenuItem = menu.findItem(R.id.menu_showsubscriptiononly);


    Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);

    TapTargetView.showFor(getActivity(),                 // `this` is an Activity
            TapTarget.forToolbarMenuItem(toolbar, R.id.menu_showsubscriptiononly, getText(R.string.taptarget_subscribeview_title), getText(R.string.taptarget_subscribeview_description))
                    // All options below are optional
                    .outerCircleColor(R.color.colorPrimary)      // Specify a color for the outer circle
                    .targetCircleColor(R.color.white)   // Specify a color for the target circle
                    .titleTextSize(30)                  // Specify the size (in sp) of the title text
                    .titleTextColor(R.color.white)      // Specify the color of the title text
                    .descriptionTextSize(20)            // Specify the size (in sp) of the description text
                    .descriptionTextColor(R.color.white)  // Specify the color of the description text
                    .textColor(R.color.white)            // Specify a color for both the title and description text
                    .dimColor(R.color.white)            // If set, will dim behind the view with 30% opacity of the given color
                    .drawShadow(true)                   // Whether to draw a drop shadow or not
                    .cancelable(true)                  // Whether tapping outside the outer circle dismisses the view
                    .tintTarget(true)                   // Whether to tint the target view's color
                    .transparentTarget(false),        // Specify whether the target is transparent (displays the content underneath)
            //.icon(Drawable),                    // Specify a custom drawable to draw as the target
            new TapTargetView.Listener() {          // The listener can listen for regular clicks, long clicks or cancels` etc...

@squarenotch
Copy link
Author

@xiphirx Apologies, this seems to be an issue with the menu element itself. It seems an actionViewClass is needed for the method getActionView to work. The library is now working with forView(MenuItemCompat.getActionView(MenuItem)

Thank you

@xiphirx xiphirx closed this as completed Nov 21, 2016
@squarenotch
Copy link
Author

@xiphirx It is worth noting however that this seems to introduce a problem as only menu items with an ActionViewClass will work. This is fine for something like a search action but for a standard menu item, im at a total loss. Appreciate the work.

@xiphirx
Copy link
Collaborator

xiphirx commented Nov 21, 2016

I'm skeptical that is actually the case. It seems like something else is going on since the sample app utilizes the forToolbarMenuItem function without issue.

@squarenotch
Copy link
Author

@xiphirx I have used that function as per the sample app without a problem. The sample app calls this in onCreate within an activity. I am calling in the onPrepareOptionsMenu within a fragment as the visibility is changing there. I will dive further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants