2012-05-26 57 views
10

Có thể xóa các nút thu phóng enter image description here không? Hiển thị của nó khi tôi phóng to WebView. Tôi cần điều khiển thu phóng mà không cần các nút này. Tôi đang sử dụng Android 2.3.Cách xóa nút thu phóng trên chế độ xem web trên Android?

tôi đã sử dụng dưới mã,

WebView webview = (WebView) findViewById(R.id.webview); 
webview.getSettings().setBuiltInZoomControls(false); 
webview.getSettings().setJavaScriptEnabled(true); 
FrameLayout mContentView = (FrameLayout) getWindow(). 
     getDecorView().findViewById(android.R.id.content); 
final View zoom = webview.getZoomControls(); 
mContentView.addView(zoom, ZOOM_PARAMS); 
zoom.setVisibility(View.GONE); 
+0

chúng ta có thể thảo luận ở đây http://chat.stackoverflow.com/rooms/10629/agarwal –

+0

Vâng chắc chắn. Tôi sẽ tham gia. – bharath

+0

@bharath u có thể giúp tôi fr [this] (http://stackoverflow.com/questions/11777116/enable-zoom-for-all-pages-of-an-android-application) –

Trả lời

5

Cuối cùng câu trả lời của tôi là, nó không thể để ẩn/loại bỏ những của nút trên WebView trong Android 2.3.

21
getSettings().setBuiltInZoomControls(false); 

sử dụng dòng trên mã để loại bỏ các nút zoom.

Mở API> = 11, bạn có thể sử dụng:

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

Cập nhật ::: Nếu bạn muốn có zoom in/out mà không cần điều khiển zoom sau đó sử dụng đoạn mã sau (sao chép từ here)

public class Main extends Activity { 
  private WebView myWebView; 
  private static final FrameLayout.LayoutParams ZOOM_PARAMS = 
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 
ViewGroup.LayoutParams.WRAP_CONTENT, 
Gravity.BOTTOM); 

  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.webview); 
    myWebView = (WebView)findViewById(R.id.webView); 

    FrameLayout mContentView = (FrameLayout) getWindow(). 
    getDecorView().findViewById(android.R.id.content); 
    final View zoom = myWebView.getZoomControls(); 
    mContentView.addView(zoom, ZOOM_PARAMS); 
    zoom.setVisibility(View.GONE); 

    myWebView.loadUrl("http://www.almondmendoza.com"); 
  } 
} 
3

Làm theo mã này. Nó sẽ giúp bạn.

Main.java

WebView wv = (WebView) findViewById(R.id.webview1) ; 
    WebSettings webSettings = wv.getSettings(); 
    webSettings.setBuiltInZoomControls(false); 
    wv.loadUrl(url); 
+0

Tốt nhất, điều này sẽ * bật * các điều khiển thu phóng. – CommonsWare

+0

thay đổi giá trị boolean thành false –

0

Đây là một giải pháp:

if (ev.getAction() == MotionEvent.ACTION_DOWN || 
     ev.getAction() == MotionEvent.ACTION_POINTER_DOWN || 
     ev.getAction() == MotionEvent.ACTION_POINTER_1_DOWN || 
     ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN || 
     ev.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) { 
    if (multiTouchZoom && !buttonsZoom) { 
     if (ev.getPointerCount() > 1) { 
      getSettings().setBuiltInZoomControls(true); 
      getSettings().setSupportZoom(true); 
     } else { 
      getSettings().setBuiltInZoomControls(false); 
      getSettings().setSupportZoom(false); 
     } 
    } 
} 

if (!multiTouchZoom && buttonsZoom) { 
    if (getPointerCount(ev) > 1) { 
     return true; 
    } 
} 

Trong trường hợp của bạn multiTouchZoom là đúng và buttonsZoom là sai.

Tôi tìm thấy nó ở đây enable/disable zoom in Android WebView và nó đã làm việc cho tôi.

+0

multiTouchZoom và buttonsZoom biến là gì? – jayellos

+0

@jayellos thay thế chúng bằng các giá trị boolean của bạn. Nếu bạn muốn thu phóng đa chạm, hãy thay thế 'multiTouchZoom' thành true. Nếu bạn cần hiển thị các nút thu phóng, hãy thay thế 'nútZoom' bằng true. Nếu không, hãy thay bằng false. –

+0

giải pháp này sẽ hoạt động http://stackoverflow.com/a/11901948/998732 – jayellos

7

Thay đổi này trên AndroidManifest của bạn:

android:minSdkVersion="8" 

này:

android:minSdkVersion="11" 

vì sử dụng này trong cài đặt xem web của bạn:

getSettings().setBuiltInZoomControls(true); 
    getSettings().setDisplayZoomControls(false); 
1

Chỉ cần thêm dòng này:

webSettings.setDisplayZoomControls(false); 
+0

Người hỏi về Android 2.3, điều này là không thể với 2.3 – VSG24

1

các nút thu phóng có thể được xóa bằng cách triển khai chế độ xem web tùy chỉnh của riêng bạn và sử dụng tính năng phản chiếu để có các điều khiển thu phóng được tích hợp sẵn và không hiển thị cho API dưới 11 (Honeycomb). Mã này là như vậy, hoạt động cho tất cả các API tối đa android nougat;

public class CustomWebView extends WebView{ 

    private ZoomButtonsController zoom_controll = null; 

    public CustomWebView(Context context) { 
     this(context, null); 
    } 

    public CustomWebView(Context context, AttributeSet attrs) { 
     this(context, attrs, android.R.attr.webViewStyle); 
    } 

    public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     initWebSettings(); 
    } 

    @SuppressLint("NewApi") 
    private void initWebSettings() { 
     WebSettings webSettings = getSettings(); 

     webSettings.setSupportZoom(true); 
     webSettings.setBuiltInZoomControls(true); 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
      webSettings.setAllowContentAccess(true); 
      webSettings.setDisplayZoomControls(false); 

     } else { 
      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 event) { 
     if(zoom_controll != null) 
      zoom_controll.getZoomControls().setVisibility(View.GONE); 
     return super.onTouchEvent(event); 
    } 

} 
1

Nếu bạn muốn vô hiệu hóa chỉ điều khiển zoom sử dụng này: webView.getSettings().setDisplayZoomControls(false);

Các vấn đề liên quan