Reputation: 1619
I'm using the MaterialShowcaseView to give users an overview of my app. set a target for the showcase, it must be a View
. Below is an example of a sequence:
String SHOWCASE_ID = getString(R.string.showcase_id);
ShowcaseConfig config = new ShowcaseConfig();
config.setDelay(500); // half second between each showcase view
MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, SHOWCASE_ID);
sequence.setConfig(config);
...
sequence.addSequenceItem(
new MaterialShowcaseView.Builder(this)
.setTarget(findViewById(R.id.navigation_header))
.setDismissText(getString("GOT IT"))
.setTitleText(getString(R.string.onboarding_navigation_header_title))
.setContentText(getString(R.string.onboarding_navigation_header_content))
.withRectangleShape(false)
.build());
...
sequence.start();
In this example, I'm targeting the navigation header of the following NavigationView
:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/main_navigation"
app:headerLayout="@layout/nav_header"/>
How would I get the menu in the snippet above as a View
so I can pass that intosetTarget()
for my showcase sequence?
I have tried using just the NavigationView
, but that targets both the header layout and the menu. I have also tried getting a group of the menu by ID (findViewById(R.id.menu_group_id)
), but I don't believe the menu group is technically a View
. I can get the menu via NavigationView.getMenu()
, but that returns a Menu
object. Any ideas?
Edit: The entire menu needs to be targeted. On a side note,this NavigationView
exists in a DrawerLayout
, if that changes anything.
Upvotes: 2
Views: 114
Reputation: 13539
There is no direct way to get the view reference of menu group in NavigationView. You could remove or hide the header view at runtime when targets NavigationView, and add or show the header view again when targets other.
you could use getheaderview to get the header and call:
your_header.setVisibility(View.GONE) //hide
your_header.setVisibility(View.VISIBLE) //show
Upvotes: 1
Reputation: 3777
You can access the menu items by using them as action views. Set the actionViewClass
in your menu.xml
like so:
<item
...
app:actionViewClass="android.support.design.widget.NavigationView"
/>
And then in your activity:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
...
sequence.addSequenceItem(
new MaterialShowcaseView.Builder(this)
.setTarget(findViewById(R.id.navigation_header))
.setDismissText(getString("GOT IT"))
.setTitleText(getString(R.string.onboarding_navigation_header_title))
.setContentText(getString(R.string.onboarding_navigation_header_content))
.withRectangleShape(false)
.build());
...
return true;
}
Upvotes: 0