I have an activity with a layout like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<include layout="@layout/window_title" />
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_below="@+id/linear_layout"/>
</RelativeLayout>
Here is how I'm configuring it:
// Enable JavaScript.
WebView myWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Settings so page loads zoomed-out all the way.
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
Here's the version setting from my manifest file:
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
I'm trying to load this page in the WebView:
https://new.livestream.com/lcboise
The page loads just fine, but I can't pinch to zoom. I've tried different combinations of the WebView settings (above, including others not listed) but it just won't zoom.
Observations:
1) Loading up a different page I'm using (https://lcboise.infellowship.com/UserLogin) in the EXACT same WebView allows me to zoom.
2) My main test device, where is DOES NOT work, is a HTC One running v4.4.3 of Android.
3) I can load, and zoom, the livestream page on an older test device I'm using that's running v2.3.3 of Android.
Is it possible that something in the page itself is breaking the WebView running on the HTC One? If so, any guesses as to might be doing it?
Update [SOLUTION]:
Here is what I had to add to my WebView to get pinch-to-zoom to work:
myWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
String javascript="javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'initial-scale=1.0,maximum-scale=10.0');";
view.loadUrl(javascript);
}
});