Troy
Troy

Reputation: 21872

How can I prevent horizontal scrolling in an Android Cordova app?

With earlier versions of Cordova (pre 5.0, pre-4.0 android), I could prevent horizontal scrolling by doing the following:

public void onCreate(Bundle savedInstanceState) {
    ...
    disablehorizontalScrolling();
    ....
}
private void disableHorizontalScrolling() {
    appView.setHorizontalScrollBarEnabled(false);
    appView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    appView.setOverScrollMode(View.OVER_SCROLL_NEVER);
}

After upgrading to Cordova 5.0 today, none of those methods are available anymore on CordovaWebView...

What is the modern replacement for the above?

Upvotes: 1

Views: 233

Answers (1)

Troy
Troy

Reputation: 21872

I found the answer after poking around a bit.

CordovaWebView (now CordovaWebViewImpl) no longer extends WebView (or anything else). The WebView object, itself, can now be accessed via appView.getEngine().getView().

So, the modern replacement for the old code is

...
private void disableHorizontalScrolling() {
    WebView view = (WebView)appView.getEngine().getView();
    view.setHorizontalScrollBarEnabled(false);
    view.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    view.setOverScrollMode(View.OVER_SCROLL_NEVER);
}

Upvotes: 2

Related Questions