2017-07-25 74 views
1

我有webView的活動。這裏佈局的xml:Android 8:WebView - 垂直滾動條 - 不正確的工作

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <WebView 
     android:id="@+id/webview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

這裏活動代碼:

public class TestActivity extends AppCompatActivity { 
    public static final String HTML_TEXT = "HTML_TEXT"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.test_activity); 
     String htmlText = getIntent().getExtras().getString(HTML_TEXT); 
     WebView webview = (WebView) findViewById(R.id.webview); 
     webview.getSettings().setJavaScriptEnabled(true); 

     String resultHTML = "<html><head><meta charset=utf-8></head><body>" + htmlText + "</body></html>"; 
     webview.loadDataWithBaseURL("fake://", resultHTML, "text/html", StringUtil.encodingUTF8, null); 
    } 
} 

而且這裏的結果是:

enter image description here

而且,你可以在右側顯示的成功看到滾動條滾動時。 此應用爲Android 4.0,5.0,6.0,7.0。好。

但在Android 8.0(模擬器)上滾動到項目「測試很多帖子7/15」(大約一半屏幕)滾動條是隱藏的。我滾動到屏幕底部,但滾動條不顯示。

這導致:

enter image description here

和滾動到屏幕底部(滾動條是隱藏的):

enter image description here

如何解決這一問題?

+0

任何成功?我有同樣的問題... – Alessandro

回答

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"); 
} 
+0

沒有幫助。同樣的結果。 – Alex