Stefano Vuerich
Stefano Vuerich

Reputation: 996

Android WebView density issue

Got some problems with the WebView class. I've got a WebView inside a RelativeLayout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webViewFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF00"
android:orientation="vertical" >

<WebView
    android:id="@+id/mWebView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" 
    android:background="#0000FF"/>

<Button
    android:id="@+id/adminBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Admin" />

</RelativeLayout>

The WebView is contained in a Fragment, code is this

public class WebViewFragment extends Fragment {

private WebView webView;
private Button adminBtn;
private String url = "http://www.my-local.guide"

@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.webview_fragment_layout,
            container, false);

    webView = (WebView) rootView.findViewById(R.id.mWebView);

    webView.getSettings().setSupportZoom(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDisplayZoomControls(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setInitialScale(120);

    webView.setWebViewClient(new WebViewClient() {
    });
    webView.loadUrl(url);

    adminBtn = (Button) rootView.findViewById(R.id.adminBtn);
    adminBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showCheckPasswordDialog();
        }
    });

    return rootView;
}

public static WebViewFragment get() {
    WebViewFragment fr = new WebViewFragment();
    return fr;
}

private void showCheckPasswordDialog() {

    CheckPasswordDialog checkPasswordDialog = CheckPasswordDialog.get();
    checkPasswordDialog.show(getFragmentManager(), SHOW_PASSWORD_DIALOG);
}

}

It seems like the WebView scales his width to 960px. I write a js script on the page and it tells me that page's width is 960px. I need to set a larger page's width to use Bootstrap as framework in my embedded websites. Using google.com as url anyway I can get all the screen's width, so I'm guessing if I have to use specific css rules for 960ps width or if I can modify the WebView's width

thank you for your time

Upvotes: 0

Views: 901

Answers (1)

Stefano Vuerich
Stefano Vuerich

Reputation: 996

Finally I fix it, I was adding to many functions that was overriding themselves

webView = (WebView) rootView.findViewById(R.id.mWebView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setInitialScale(100);

this code works

Upvotes: 1

Related Questions