在webview android中禁用双击放大

时间:2014-02-07 13:22:14

标签: android webview

这个问题已经在stackoverflow中有解决方案,但对不起家伙我无法用我的代码解决问题。请帮助我禁用双击或任何其他缩放活动......

User_reg.java

package com.example.samworkshops;

import android.os.Bundle;
import android.os.SystemClock;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class User_reg extends Activity {
 private WebView webView;
 final Activity activity = this;


@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

        setContentView(R.layout.activity_user);
        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


        webView = (WebView)findViewById(R.id.webView1);
        webView.requestFocusFromTouch();
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setUseWideViewPort(true);                                                         
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setBuiltInZoomControls(false);
        webView.setHorizontalScrollBarEnabled(false);

        webView.setInitialScale(90);

        webView.loadUrl("http://app.samworkshops.org/User_Reg.aspx");

        webView.setVisibility(View.INVISIBLE);
        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);

                if(progress == 100)
                    activity.setTitle(R.string.title_activity_user_reg);
            }
        });

        webView.setBackgroundColor(Color.parseColor("black"));


        webView.setWebViewClient(new WebViewClient() {


            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                // Handle the error
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }


            @Override
            public void onPageFinished(WebView view, String url) {
                StringBuilder builder = new StringBuilder("");


                    builder.append("javascript:document.getElementById('Image3').style.visibility= 'hidden';");
                    builder.append("javascript:document.getElementById('Image3').style.display   = 'none'  ;");
view.loadUrl(builder.toString());

                webView.setVisibility(View.VISIBLE);
                SystemClock.sleep(2000);

            }


        });

    }

}

1 个答案:

答案 0 :(得分:0)

试试这个控件会有所帮助:

webView .getSettings().setDisplayZoomControls(false);
webView .getSettings().setBuiltInZoomControls(false);
webView .getSettings().setSupportZoom (false);