MaterialShowcaseView
MaterialShowcaseView copied to clipboard
Dismiss the Showcase on Back button press when inside a Fragment
I tried to implement the ShowcaseView inside a Fragment. The problem I noticed is that when I press the back button the ShowcaseView doesn't disappear. So the problem arises that, the previous fragment is loaded and the ShowcaseView is pointing to a random UI element.
same problem here
Hi, I resolved this problem adding a list of MaterialShowcaseViews in a base fragment class when I create the sequence items, and overriding the onbackpress on the activity to remove all views in this list off the screen:
for (MaterialShowcaseView item : mHelpViews) {
item.removeFromWindow();
}
You just need to consider that removing the view will call the dismiss listener, if you have one for any MaterialShowcaseView.
@shipjacker Can't we do just item.hide()
in this case?
I did the same as @shipjacker . First, I use a global variable and whenever I create a MaterialShowCaseView assignit there. Then I Just override the onPause method of the fragment to hide the golbalMaterialShowCase if it's not null and is showing.
removeFromWindow works for showcaseview, but not for sequence, since the items are in a private queue, and not accessible. So i inherited it, and manually add items to a list. the remove() method is called when the onPause event is fired from my fragment so that it doesn't point at random UI elements
public class myMaterialSequence extends MaterialShowcaseSequence {
private ArrayList<MaterialShowcaseView> sequenceItems;
Activity activity;
public myMaterialSequence(Activity activity, String ID) {
super(activity,ID);
sequenceItems=new ArrayList<>();
this.activity = activity;
ShowcaseConfig config = new ShowcaseConfig();
config.setDelay(200); // delay between each showcase view
config.setFadeDuration(300);
}
public void addItem(View target, String title, String desc, String dismissText){
MaterialShowcaseView sequenceItem = new MaterialShowcaseView.Builder(activity)
.setTarget(target)
.setTitleText(title)
.setDismissText(dismissText)
.setContentText(desc)
.setSequence(true)
.build();
this.addSequenceItem(sequenceItem);
sequenceItems.add(sequenceItem);
}
public void remove(){
for (MaterialShowcaseView item : sequenceItems) {
Log.e("SEQUENCE","Remove"+item.getId()+","+item.getTransitionName());
item.removeFromWindow();
}
}
}