2016-02-26 70 views
0

你好我在使用WebView在Android中,我想放大加載到我的網頁視圖的頁面。我使用以下設置:如何在android中縮放網頁查看頁面

wb.getSetting().setBuiltInZoomControls(true); 
    wb.getSetting().setSupportZoom(true); 
    wb.loadUrl("https://www.mywebsite.com/"); 

之前的網頁加載正確的變焦控制節目,但網頁後加載變焦控制了。

Screen shot

回答

0
wb.getSettings().setBuiltInZoomControls(true); 
wb.getSettings().setDisplayZoomControls(false); 
0

試試這個:

public class WebViewController extends WebView { 

    private ZoomButtonsController zoom_controll = null; 

    public WebViewController(Context context) { 
     super(context); 
     disableControls(); 
    } 

    public WebViewController(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     disableControls(); 
    } 

    public WebViewController(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     disableControls(); 
    } 

    /** 
    * Disable the controls 
    */ 
    private void disableControls(){ 
     if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { 
      // Use the API 11+ calls to disable the controls 
      this.getSettings().setBuiltInZoomControls(true); 
      this.getSettings().setDisplayZoomControls(false); 
     } else { 
      // Use the reflection magic to make it work on earlier APIs 
      getControlls(); 
     } 
    } 

    /** 
    * This is where the magic happens :D 
    */ 
    private void getControlls() { 
     try { 
      Class webview = Class.forName("android.webkit.WebView"); 
      Method method = webview.getMethod("getZoomButtonsController"); 
      zoom_controll = (ZoomButtonsController) method.invoke(this, null); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     super.onTouchEvent(ev); 
     if (zoom_controll != null){ 
      // Hide the controlls AFTER they where made visible by the default implementation. 
      zoom_controll.setVisible(false); 
     } 
     return true; 
    } 
}