How to disable mouse wheel scrolling in WebView?

223 views
Skip to first unread message

Vivek Daramwal

unread,
Nov 6, 2017, 12:59:11 PM11/6/17
to Chromium-dev
I have a ScrollView which can contain multiple WebViews. I know keeping scrollable view inside another is not the right way but this is the basic requirement for my app. I have disabled vertical scrolling (using setVerticalScrollBarEnabled()) in all my WebViews. Also disabled focusability in ScrollView's children using descendantFocusability=blocksDescendants. I want only ScrollView to scroll.
There is no problem on Android device when I try scrolling as it is done on touch. But, the problem is when I run my APK inside Chromebook and try to do mouse wheel scrolling over WebView, ScrollView does not scroll. Chromebook Trackpad works fine though, it scrolls when i scroll over WebView. Problem is only with mouse wheel scrolling. It looks like WebView is consuming the scroll events and its not bubbling up to ScrollView. Ideally mouse wheel scrolling and Trackpad scrolling are supposed to work the same way. 

Can someone suggest a solution to this problem?

Vivek Daramwal

unread,
Nov 7, 2017, 1:24:08 AM11/7/17
to Chromium-dev
I found the workaround for this. Just subclass WebView and override onGenericMotionEvent method.
   
public class PreviewWebView extends WebView {
   
       
public PreviewWebView(Context context) {
           
super(context);
       
}
   
       
public PreviewWebView(Context context, AttributeSet attrs, int defStyle) {
           
super(context, attrs, defStyle);
       
}
   
       
public PreviewWebView(Context context, AttributeSet attrs) {
           
super(context, attrs);
       
}
   
       
@Override
       
public boolean onGenericMotionEvent(MotionEvent event) {
           
return false;
       
}
   
}
Reply all
Reply to author
Forward
0 new messages