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");
}
});