Man*_*anu 5 android webview cordova
我正在使用PhoneGap开发应用程序.我无法在webview中启用内置放大/缩小功能.
我在onCreate函数中使用了以下代码
WebView web = (WebView) findViewById(R.id.webview);
web.getSettings().setBuiltInZoomControls(true);
Run Code Online (Sandbox Code Playgroud)
但它没有用.
而Activity类是
activity_main.xml中
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Run Code Online (Sandbox Code Playgroud)
Swe*_*r ツ 19
检查您是否没有包装Webview 的ScrollView.
似乎ScrollView妨碍了捏手势.
要修复它,只需将您的Webview放在ScrollView外面,然后使用相同的行:
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);
Run Code Online (Sandbox Code Playgroud)
Cordova 5.1 的情况略有变化(我认为它实际上在 5.0 中发生了变化)。
要为 Cordova 5 启用 Android 缩放,请添加以下几行:
Run Code Online (Sandbox Code Playgroud)import android.webkit.WebView; import android.webkit.WebSettings; import android.webkit.WebSettings.ZoomDensity;
还有这些
Run Code Online (Sandbox Code Playgroud)WebView webView = (WebView) appView.getEngine().getView(); WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setSupportZoom(true);
您的src/com/YOURPACKAGE.java
文件的完整示例:
package com.YOURPACKAGE;
import android.os.Bundle;
import org.apache.cordova.*;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.webkit.WebSettings.ZoomDensity;
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
WebView webView = (WebView) appView.getEngine().getView();
WebSettings settings = webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
//settings.setDefaultZoom(ZoomDensity.FAR);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15501 次 |
最近记录: |