在Android webview中强制滚动条有哪些选项?

时间:2014-05-07 12:37:11

标签: android android-webview

我正在为Android应用构建一个webview。

对于桌面浏览器,我可以在overflow-y: scroll标记上添加<body>以强制滚动条跟踪到页面上,但这不会强制实际滚动条。

我被要求强迫滚动条&#34;在应用程序中,但我担心它会做到这一点,放置一个轨道而不是实际的滚动条。

有没有办法强制滚动条可见,无论加载webview的Android版本是什么?

Android端和HTML + CSS端有哪些选项?

3 个答案:

答案 0 :(得分:1)

在您的代码中,您可以尝试:

webView.setScrollbarFadingEnabled(false);

这将禁止滚动条逐渐消失。

答案 1 :(得分:1)

截至目前,最好的方法是在xml中使用android:fadeScrollbars="false",这相当于java代码中的ScrollView.setScrollbarFadingEnabled(false);

设置android:scrollbarFadeDuration="0"可以解决问题。

你的onCreate()方法中的

例如::试试这个:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_web_view_layout); 

    browser = (WebView)findViewById(R.id.your_webview);
    WebSettings mWebSettings = browser.getSettings();
    mWebSettings.setBuiltInZoomControls(true);
    browser.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    browser.setScrollbarFadingEnabled(false);
    browser.loadUrl("file:///android_asset/index.html");
}

尝试在WebView中使用ScrollView,并使用android:fadeScrollbars="false"代替ScrollView

<强>例如

<ScrollView android:layout_width="fill_parent" 
            android:layout_height="86px" 
            android:id="@+id/scrollTxtDescription"
            android:fadeScrollbars="false"
            android:layout_below="@id/txtLieuPromo1" 
            android:layout_alignLeft="@id/txtLieuPromo1">

            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/layoutTxtDescription"
                >

                <WebView android:id="@+id/txtDescription" 
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    />
            </LinearLayout>
        </ScrollView>

答案 2 :(得分:1)

只需将活动中的这些行添加到webview中,无需在xml中添加任何内容,这将导致水平和垂直滚动。

     webview.getSettings().setLoadWithOverviewMode(true);

                    webview.getSettings().setJavaScriptEnabled(true);

                    webview.loadData("Your Content to show in the webview,
                            "text/html; charset=UTF-8", null);

尝试使用此代码,希望您能获得解决方案。