我目前正在android中构建一个Web应用程序.我的应用程序在webview中运行,并通过iframe加载第三方内容.iframe大小是固定的,并且不应被加载的内容更改.
在桌面Chrome浏览器中,它工作正常,加载内容的溢出部分可以通过滚动条滚动.但是,在android webview中,iframe会根据加载的内容调整自身大小,这会导致页面布局混乱.
还有其他人遇到过同样的问题吗?
在Android开发者参考说,无论是WebView.PictureListener界面和它的onNewPicture()方法已过时.
很好,但需要知道WebView何时渲染图片仍然存在.有没有其他方法来实现这一目标?
webview的历史还没有清除......下面的代码出了什么问题?
Web视图创建
mWebViewReport=(WebView)findViewById(R.id.report_page);
mWebViewReport.setWebViewClient(new HelloWebViewClient());
mWebViewReport.getSettings().setBuiltInZoomControls(true);
Run Code Online (Sandbox Code Playgroud)
单击帮助按钮时加载帮助文件
mWebViewReport.loadUrl("file:///android_asset/help.html");
mWebViewReport.clearHistory();
mWebViewReport.clearCache(true);
Run Code Online (Sandbox Code Playgroud)
单击摘要按钮时加载摘要文件
mWebViewReport.loadUrl("file:///android_asset/summary.html");
//On back button click
if (mWebViewReport.canGoBack()) {
mWebViewReport.goBack();
return ;
}
Run Code Online (Sandbox Code Playgroud)
在这里,我也可以看到帮助页面......
我正在尝试从我的webview中的javascript界面开始一个活动.这个例子显示了一个祝酒词.我怎么能叫一个班而不是一个吐司呢?
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
这对于html页面.
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
Run Code Online (Sandbox Code Playgroud)
如何在网页浏览中启用Cookie?
我试着用
CookieManager.getInstance().setAcceptCookie(true);
Run Code Online (Sandbox Code Playgroud)
就在调用WebView.loadUrl()之前它并没有工作,因为我从网站上得到一个html页面错误,说需要启用cookie.
我不明白的是,cookieManager如何知道启用cookie的webview?
如果我在屏幕上有两个webview的活动,我只想要其中一个webview启用cookie,那怎么可能使用CookieManager?
我觉得我错过了什么?我找不到像webView.setCookieManager或Cookiemanager.setWebView(webview)这样的方法
谢谢
首先,我尝试了许多破坏Android中的webview的例子.
例如: Android中的内存泄漏
虽然我在onDestroy()中销毁webview并以编程方式声明了webview,但内存泄漏问题也将在我的Android设备中发生.
以下是我的编码..
public class MainActivity extends Activity {
private FrameLayout mWebContainer;
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
mWebContainer = (FrameLayout) findViewById(R.id.web_container);
mWebView = new WebView(getApplicationContext());
mWebContainer.addView(mWebView);
}
@Override
protected void onDestroy() {
super.onDestroy();
mWebContainer.removeAllViews();
mWebView.clearHistory();
mWebView.clearCache(true);
mWebView.clearView();
mWebView.destroy();
mWebView = null;
}
Run Code Online (Sandbox Code Playgroud)
有人帮帮我..谢谢..
任何人请告诉我方法public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)和方法之间的区别public boolean shouldOverrideUrlLoading(WebView view, String url).
我正在创建一个Android应用程序,其中获取一个字符串作为我的WebView.I 中的点击事件的响应.我想存储此字符串并显示它.我看到了这两种方法.我尝试使用shouldOverrideUrlLoading哪个返回重定向网址当我检查创建一个示例应用程序使用google.com作为我加载的网址WebView并单击菜单.
谁能告诉我两种方法之间的区别以及我应该使用哪种方法?
我正在尝试使用WebView制作应用程序,但该网站正在使用https,但内容(例如mp3文件)使用http,因此Android Lollipop将不会加载它,因为它是"混合内容".我试图使用onReceivedSslError handler.proceed();,但它没有加载任何东西.有办法解决吗?或者我可以只加载所有网站使用http,所以它没有显示任何错误?
我会尽量做空 - 所以我正在制作这个应用程序,将图像上传到自定义Webview,绘制画布并保存.现在我成功地执行了所有操作,直至保存它.我尝试了很多不同的方法,但都没有.
我保存未经编辑的图像Url:
public void DownloadFromUrl(String fileName) { //this is the downloader method
try {
URL url = new URL(wv2.getUrl()); //you can write here any link
File file = new File(fileName);
Canvas canvas = new Canvas();
wv2.draw(canvas );
long startTime = System.currentTimeMillis();
Log.d("ImageManager", "download begining");
Log.d("ImageManager", "download url:" + url);
Log.d("ImageManager", "downloaded file name:" + fileName);
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int …Run Code Online (Sandbox Code Playgroud) 我一直在研究一个问题,即在一个WebView(带有返回值)中对JavaScript进行同步调用,并试图缩小它为什么不起作用的地点和原因.WebView当主线程正在等待来自它的响应时,似乎线程正在阻塞 - 自从在WebView单独的线程上运行以来不应该是这种情况.
我把这个小样本放在一起,相当清楚地展示了它(我希望):
main.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"
android:weightSum="1">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
MyActivity.java:
package com.example.myapp;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.JavascriptInterface;
import android.webkit.WebViewClient;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class MyActivity extends Activity {
public final static String TAG = "MyActivity";
private WebView webView;
private JSInterface JS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView)findViewById(R.id.webView);
JS = …Run Code Online (Sandbox Code Playgroud)