zoom in phonegap for android
How do I enable zoom on my phonegap app for android users?
I tried to customize "Sample/src/com/phonegap/Sample/Sample.java" but it still just doesn't work:
Any ideas?
package com.phonegap.Sample;
import android.app.Activity;
import android.os.Bundle;
import com.phonegap.*;
import android.webkit.WebSettings;
public class Sample extends DroidGap
{
@Override
开发者_C百科public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
WebSettings ws = super.appView.getSettings();
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
}
}
This has worked for me, the above solution didn't.
package com.my.app;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebSettings.ZoomDensity;
import com.phonegap.*;
public class MyDroidActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
WebSettings settings = appView.getSettings();
settings.setBuiltInZoomControls(false);
settings.setSupportZoom(false);
settings.setDefaultZoom(ZoomDensity.FAR);
}
}
This is where I found it, the credit goes to them! https://github.com/phonegap/phonegap-android/issues/120
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=0.8, user-scalable=1" />
That worked for me ;).
It should be placed in the meta section of your html pages
Erks answer didn't worked for me (thought I wanted only to scale, no pinch zooming).
But this worked: How to change PhoneGap's screen size?
EDIT: It was long time ago since I played with this, so I will just copy-paste answer (just in case if for some reason stackoverflow decides to remove that link as stated in comment).
I found a way to do that. I already had tried by using a meta viewport, but I guess I don't put everything that is necessary.
Just put this meta tag below and everything should be fine.
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, target-densityDpi=device-dpi" />
精彩评论