我有一个webview,我正在尝试将简单的UTF-8文本加载到其中.
mWebView.loadData("?????????????", "text/html", "UTF-8");
Run Code Online (Sandbox Code Playgroud)
但WebView显示ANSI/ASCII垃圾.
显然是编码问题,但在告诉webview显示Unicode文本时我缺少什么?
这是一个HelloWorld应用程序.
我试图完成一些非常简单的事情,但我没有找到关于此的好文档.我有一个webView,我需要加载一个需要POST数据的页面.看起来像一个简单的过程,但我找不到在webView中显示结果的方法.
这个过程应该很简单:
查询(使用POST数据) - > webserver - > HTML response - > WebView.
我可以使用DefaultHttpClient提交数据,但这不能在WebView中显示.
有什么建议?
非常感谢
解
private static final String URL_STRING = "http://www.yoursite.com/postreceiver";
public void postData() throws IOException, ClientProtocolException {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("foo", "12345"));
nameValuePairs.add(new BasicNameValuePair("bar", "23456"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL_STRING);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String data = new BasicResponseHandler().handleResponse(response);
mWebView.loadData(data, "text/html", "utf-8");
}
Run Code Online (Sandbox Code Playgroud) 如何WebView在Android中实现Scroll Listener
我试过这个,但它没有调用我Log.i滚动webview.
package com.example.webview.full.width;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
public class scorllableWebview extends WebView implements OnScrollListener {
Context ctx;
AttributeSet atrs;
public scorllableWebview(Context context) {
super(context);
ctx = context;
}
public scorllableWebview(Context context, AttributeSet atters){
super(context, atters);
ctx = context;
atrs = atters;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
Log.i("onScroll", "Called");
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
Log.i("onScrollStateChanged", …Run Code Online (Sandbox Code Playgroud) 我<input type="file">在android webview上使用了它.我得到了它的工作感谢这个线程:
WebView中的文件上传
但接受的答案(或任何其他)不再适用于android 4.4 kitkat webview.
有谁知道如何解决它?
它也不适用于目标18.
我看了一些android 4.4源代码,似乎WebChromeClient没有改变,但我认为setWebChromeClient不再适用于kitkat webview,或者至少不是这个openFileChooser功能.
我想使用"file:///"将本地html加载到WebView中,因为它不允许使用cookie.有没有办法使用像"localhost"这样的东西?
其次,我找不到在getSettings()中启用cookie的方法.因为使用"file:///"时不允许使用cookie.
我有一个WebView(Android 3.0+)的问题,WebView在显示我的黑色背景("闪烁")之前总是显示白色背景.这是我简单的测试代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.setBackgroundColor(Color.BLACK);
setContentView(webView);
loadWebView(webView);
webView.loadDataWithBaseURL("localhost://", "<html><head>" +
"<style>body {background-color: #000}img{max-width:100%}</style></head>" +
"<body>" +
"<img src=\"http://developer.android.com/images/practices/actionbar-phone-splitaction.png\" />" +
"</body></html>",
"text/html", "UTF-8", null);
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多解决方案来摆脱这个问题,但并不幸运.
PS:如果关闭硬件加速,则不会出现此问题.有人有同样的问题并解决了吗?
谢谢.
android webview hardware-acceleration android-3.0-honeycomb android-4.0-ice-cream-sandwich
我正在制作测试应用程序,所以在我的tableviewCell故事板中我有imageView和webView(用于显示html文本).我为imageView设置了top/left/right/height = 200的约束,它们之间的间距= 5,webView的左/右/ bot,所以我想以编程方式计算我的webView高度,然后更改单元格的高度来拉伸我的webView.但我得到了这个:
无法同时满足约束.
可能至少下列列表中的一个约束是您不想要的约束.
试试这个:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints & fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fd6f3773f90 V:[UIImageView:0x7fd6f3773e90(200)]>",
"<NSLayoutConstraint:0x7fd6f3774280 UIImageView:0x7fd6f3773e90.top == UITableViewCellContentView:0x7fd6f3462710.topMargin>",
"<NSLayoutConstraint:0x7fd6f3774320 V:[UIImageView:0x7fd6f3773e90]-(5)-[UIWebView:0x7fd6f3462800]>",
"<NSLayoutConstraint:0x7fd6f3774370 UITableViewCellContentView:0x7fd6f3462710.bottomMargin == UIWebView:0x7fd6f3462800.bottom>",
"<NSLayoutConstraint:0x7fd6f375ee40 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fd6f3462710(205)]>"
)
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我有一个带有webview的原生iOS应用程序来显示Web内容.我的应用程序中有一个固定的标题,其中包含以下属性:
#header {
height: 60px;
background-color: @mainColor;
color: #ffffff;
padding: 10px;
text-align: center;
position: fixed;
width: 100%;
z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)
在我升级到iOS 11之前一切正常.现在当我向下/向上滚动时,标题在滚动期间消失,当滚动完成时,标题再次出现.
这也可以在Xcode 8中重现.
在我的android webview我的网页加载甚至没有因为缓存的互联网,所以我想在android webview中禁用缓存,任何人都可以帮我如何做到这一点?
我在我的webview中使用以下行,但仍然无法禁用缓存.
myBrowser.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
myBrowser.getSettings().setAppCacheEnabled(false);
Run Code Online (Sandbox Code Playgroud)
如果有其他方法,请建议我
webview ×10
android ×8
ios ×2
android-4.0-ice-cream-sandwich ×1
constraints ×1
cordova ×1
css ×1
html ×1
ios11 ×1
objective-c ×1
post ×1
scrollview ×1
uitableview ×1
unicode ×1