How to add scroll bar in a phonegap application

2019-04-13 00:56发布

I'm developing an application in PhoneGap for the Android platform.

In this app the scroll bar is not displayed. How can I display a scroll bar in my application?

5条回答
我只想做你的唯一
2楼-- · 2019-04-13 01:13

Here is my example Activity that will display the scrollbars

public class MyActivity extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        super.loadUrl("file:///android_asset/www/index.html");

        // Display vertical scrollbar and hide horizontal scrollBar
        super.appView.setVerticalScrollBarEnabled(true);
        super.appView.setHorizontalScrollBarEnabled(false);
        // set scrollbar style
        super.appView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    }

}
查看更多
Anthone
3楼-- · 2019-04-13 01:25

well scrolling is the effect that cannot be seen in phonegap/cordova projects, for that purpose we can there are tools third party libraries that you can include in your project. the one that i used for my project was iscroll 4 . even this has some problems but that can be solved surfing the google groups of iscroll4 also ther is this jquery-mobile that also gives scrolling effect for phonegap projects.

查看更多
Rolldiameter
4楼-- · 2019-04-13 01:27

We have been facing the same issue. Cordova disables scroll bars on the web view in CordovaWebView.java, so we created a plugin that allows you to reenable the vertical scrollbar programmatically from JavaScript without hacking up Cordova:

mayflower.AndroidScrollbar.toggleVerticalScrollbarVisibility(true)
.then(
    function() {
        console.log('Vertical scrollbar enabled');
    }
);
查看更多
Bombasti
5楼-- · 2019-04-13 01:29

This solution does not completely solve the problem if you want to use scrolled div inside the main div.

Put others elements in absolute position over the main div.

Try this: Apache cordova on android where are scrollbars?

查看更多
Deceive 欺骗
6楼-- · 2019-04-13 01:34

I am using Cordova 5.2+ and facing the same challenge. But, I found the solution here:

  • You can go to: SystemWebViewEngine.java which located in yourAppName\platforms\android\CordovaLib\src\org\apache\cordova\SystemWebViewEngine.java

  • Then, set:

    webView.setVerticalScrollBarEnabled(true);

Hope it helps Pal!

查看更多
登录 后发表回答