-1

I want to display a showcase on overflow icon from menu.

This is my code:

ShowcaseConfig config = new ShowcaseConfig();
config.setDelay(500); // half second between each showcase view

MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, "5");

sequence.setConfig(config);
sequence.addSequenceItem(((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0),
       "Sync your data by turn on the switch", "GOT IT");

I need a reference to the View of overflow icon in order to add next showcase sequence:

sequence.addSequenceItem(?, "Click here to display menu", "GOT IT");

How to get the reference to that View?

azizbekian
  • 60,783
  • 13
  • 169
  • 249
Raghav
  • 1

2 Answers2

1

You can declare the id to the overflow icon through styles and find the view using that id

In ids.xml, declare the id

   <!--Action bar more options -->
    <item name="action_bar_more_options" type="id"/>

In Styles.xml

 <style name="Custom_ActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
        <item name="android:id">@id/action_bar_more_options</item>
    </style>



<style name="Widget_style">
<item name="android:actionOverflowButtonStyle">@style/DarkMail_ActionButtonOverflow</item>
</style>

<item name="android:actionBarWidgetTheme">@style/Widget_style</item>

Then using findViewbyId using access the view :) Hope this helps you

0

It's a bit tricky to acquire the View of the overflow icon.

This answer will point out a way to do that. To sum up, following changes should be made.

In styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="actionOverflowButtonStyle">@style/MyActionOverflowButtonStyle</item>
</style>

<style name="MyActionOverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
    <item name="android:contentDescription">@string/my_custom_content_description</item>
</style>

In strings.xml:

<string name="my_custom_content_description">some description</string>

In activity's onCreate():

// The content description used to locate the overflow button
final String overflowDesc = getString(R.string.my_custom_content_description);
// The top-level window
final ViewGroup decor = (ViewGroup) getWindow().getDecorView();
// Wait until decor view is laid out
decor.post(new Runnable() {
    @Override
    public void run() {
        // The List that contains the matching views
        final ArrayList<View> outViews = new ArrayList<>();
        // Traverse the view-hierarchy and locate the overflow button
        decor.findViewsWithText(outViews, overflowDesc,
                View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
        // Guard against any errors
        if (outViews.isEmpty()) {
            return;
        }
        // Do something with the view
        final ImageView overflowIcon = (ImageView) outViews.get(0);
        sequence.addSequenceItem(overflowIcon, "Click here to display menu", "GOT IT");
    }
});
Community
  • 1
  • 1
azizbekian
  • 60,783
  • 13
  • 169
  • 249