Maybe I found solution. I add framelayout in my view group. thank you dieter_h
Creating custom Framelayout class for override IntercepterTouchEvent
private class InterceptTouchEventLayout extends FrameLayout {
Snackbar mSnackbar;
public InterceptTouchEventLayout(Context context) {
super(context);
setLayoutParams(new CoordinatorLayout.LayoutParams(
CoordinatorLayout.LayoutParams.MATCH_PARENT,
CoordinatorLayout.LayoutParams.MATCH_PARENT));
}
public void setSnackbar(Snackbar snackbar) {
mSnackbar = snackbar;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
if (mSnackbar != null && mSnackbar.isShown()) {
mSnackbar.dismiss();
}
break;
}
return super.onInterceptTouchEvent(ev);
}
}
my xml:
<FrameLayout
...>
<ScrollView .../>
<FrameLayout .../>
</FrameLayout>
Getting FrameLayout which is top of it by
View contentView = this.findViewById(android.R.id.content);
View framLayout = ((ViewGroup) contentView).getChildAt(0);
Writing method for adding custom layout
private void addInterceptLayoutToViewGroup(Snackbar snackbar) {
View contentView = this.findViewById(android.R.id.content);
ViewGroup vg = (ViewGroup) ((ViewGroup) contentView).getChildAt(0);
if (!(vg.getChildAt(0) instanceof InterceptTouchEventLayout)) {
InterceptTouchEventLayout interceptLayout =
new InterceptTouchEventLayout(this);
interceptLayout.setSnackbar(snackbar);
for (int i = 0; i < vg.getChildCount(); i++) {
View view = vg.getChildAt(i);
vg.removeView(view);
interceptLayout.addView(view);
}
vg.addView(interceptLayout, 0);
} else {
InterceptTouchEventLayout interceptLayout =
(InterceptTouchEventLayout) vg.getChildAt(0);
interceptLayout.setSnackbar(snackbar);
}
}
So, I can use like this!!!
Snackbar snackbar = Snackbar.make(this.findViewById(android.R.id.content), "text", Snackbar.LENGTH_INDEFINITE)
.setAction("action", new View.OnClickListener() {
@Override
public void onClick(View v) {
//...
}
});
snackbar.show();
addInterceptLayoutToViewGroup(snackbar);
Honestly, My solution changes the view tree(?). After that, My xml may be..
<FrameLayout
...>
<InterceptTouchEventLayout
...>
<ScrollView .../>
<FrameLayout .../>
</InterceptTouchEventLayout>
</FrameLayout>