Web zoom control

htmlp = URLEncoder.encode(desc,"utf-8").replaceAll("\\+"," "); WebView wv=(WebView)findViewById(R.id.webView1); wv.setInitialScale(70); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setPluginsEnabled(true); wv.getSettings().setSupportZoom(true); wv.getSettings().setLoadWithOverviewMode(true); wv.getSettings().setBuiltInZoomControls(true); wv.loadData(htmlp,"text/html", "utf-8"); 

Htmlp contains HTML content (tags). Now I need to enable zoom control, but using the code above it doesn't work. I have to include something in the xml parts of the web view.

Thank you in advance

0
source share
3 answers

This works well in my case. Try this for your business.
In the manifest file.

 <uses-permission android:name="android.permission.INTERNET"> </uses-permission> 

webview.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <WebView android:id="@+id/webView" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> 

In activity ..

 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); this.setContentView(R.layout.webview); this.myWebView = (WebView) this.findViewById(R.id.webView); FrameLayout mContentView = (FrameLayout) getWindow(). getDecorView().findViewById(android.R.id.content); final View zoom = this.myWebView.getZoomControls(); mContentView.addView(zoom, ZOOM_PARAMS); zoom.setVisibility(View.GONE); this.myWebView.loadUrl("http://www.facebook.com"); } } 
0
source
  wv.getSettings().setBuiltInZoomControls(false); 

change to false

0
source

I finally solved this problem. The problem was in the design section. Just changed the layout parameter:

 WebView android:layout_width="match_parent" android:layout_height="match_parent" 
0
source

Source: https://habr.com/ru/post/984616/


All Articles