public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.a);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setBuiltInZoomControls(true); // controler
webView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);//
//changeZoomControls(weView);
//wv.setInitialScale(100);
//
webView.loadUrl("www.csdn.net");
int sysVersion = Integer.parseInt(VERSION.SDK);
if(sysVersion>=11){
setZoomControlGoneX(webView.getSettings(),new Object[]{false});
}else{
setZoomControlGone(webView);
}
//ws.setDisplayZoomControls(false);//3.0 ,3.0
}
// webview 3.0
public void setZoomControlGoneX(WebSettings view ,Object[] args){
Class classType = view.getClass();
try {
Class[] argsClass = new Class[args.length];
for (int i = 0, j = args.length; i < j; i++) {
argsClass[i] = args[i].getClass();
}
Method[] ms= classType.getMethods();
for (int i = 0; i < ms.length; i++) {
if(ms[i].getName().equals("setDisplayZoomControls")){
try {
ms[i].invoke(view, false);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
//Log.e("test", ">>"+ms[i].getName());
}
}catch (Exception e) {
e.printStackTrace();
}
}
// webview 3.0
public void setZoomControlGone(View view) {
Class classType;
Field field;
try {
classType = WebView.class;
field = classType.getDeclaredField("mZoomButtonsController");
field.setAccessible(true);
ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(view);
mZoomButtonsController.getZoomControls().setVisibility(View.GONE);
try {
field.set(view, mZoomButtonsController);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}