Can the zoom button in the lower right corner of webview be removed?
Settings. setdisplayzoomcontrols (false );// Hide the webview zoom button
There are several methods I know to center the page loaded by webview
Method 1:
Websettings settings = webview. getsettings ();
Settings. setlayoutalgorithm (layoutalgorithm.Single_column);
Layoutalgorithm is an enumeration used to control the page layout. There are three types:
1. narrow_columns: if possible, the width of all columns should not exceed the screen width.
2. Normal: normal display without any Rendering
3. single_column: enlarge all content in a column with the same width as webview.
The single_column type can be used to set the center display of the page, and the page can be zoomed in and out, but this method is not very good. Sometimes it will make your page layout look like it. I tested it and can only display the middle part, any part that exceeds the screen cannot be displayed.
Method 2:
// Set the adaptive mobile phone screen for the loaded page
Settings. setusewideviewport (true );
Settings. setloadwithoverviewmode (true );
The first method sets the window recommended for webview to true. The second method is to set the page loading mode of webview, and also to true.
This method allows your page to adapt to the resolution of the mobile phone screen. It is completely displayed on the screen and can be zoomed in or out.
Both methods have been tried. The second method is recommended.
Method 3(Mainly used for flat panel to adjust the resolution for specific screen code)
Displaymetrics metrics = new displaymetrics ();
Getwindowmanager (). getdefaultdisplay (). getmetrics (metrics );
Int mdensity = metrics. densitydpi;
If (mdensity = 120 ){
Settings. setdefazoom zoom (zoomdensity. Close );
} Else if (mdensity = 160 ){
Settings. setdefazoom zoom (zoomdensity. Medium );
} Else if (mdensity = 240 ){
Settings. setdefazoom zoom (zoomdensity. Far );
}