为了WebView在android中实现,我遇到了一个奇怪的问题.我正在尝试加载html5支持的网页WebView,但问题是默认缩放控制器无法正常工作WebView.我尝试使用以下代码.
webview.getSettings().setBuiltInZoomControls(true);
webview.invokeZoomPicker();
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙解决这个问题
早上好,我有一个专为智能手机和平板电脑设计的应用程序.当它在平板电脑上运行时,我想缩放我的webview文本,以便用户可以更好地阅读文本并填写所有空白区域(如果可能).
这是我用来做这个技巧的代码:
//Webview Zoom
if( UIUtils.isTablet(getActivity())) {
if(UIUtils.isICS()) {
webView.getSettings().setTextZoom(130);
} else {
int currentTextSizeIndex = lyricsView.getSettings().getTextSize().ordinal();
if ( currentTextSizeIndex+1 < lyricsView.getSettings().getTextSize().values().length )
webView.getSettings().setTextSize( lyricsView.getSettings().getTextSize().values()[currentTextSizeIndex+1] );
}
}
Run Code Online (Sandbox Code Playgroud)
所以我检查一下我是否在平板电脑上并检查用户正在使用哪个操作系统版本.事实上,从API Level 14我可以使用setTextZoom,它允许我以百分比(默认为100)设置页面的文本缩放.这个解决方案的可扩展性要高得多,因为我可以为用户提供按步骤+10或-10%增加或减少文本的能力.
在API级别14之前,我必须使用使用枚举作为参数的setTextSize(默认为NORMAL).TextSize是Enum,用于指定文本大小.SMALLEST是50%SMALLER是75%NORMAL是100%LARGER是150%LARGEST是200%
所以我只能使用这5个costants并且它不是那么可扩展(但它是将这个功能提供给没有ICS的90%手机的唯一方法:D).
问题是,webView.getSettings().setTextSize(TextSize.LARGER);当我在不同的平板电脑上显示文本视图时,以不同的方式行动,这真的不合适.
目前我正在测试三星Galaxy Tab和Kindle Fire.这些是GSMArena的技术规范:
显示
型TFT电容式触摸屏,16M色
尺寸 600 x 1024像素,7.0英寸(约170 ppi像素密度)
显示
型IPS TFT电容式触摸屏,16M色
尺寸 1024 x 600像素,7.0英寸(~170 ppi像素密度)
如您所见,它们具有相同的分辨率,英寸和ppi!现在,我将向您展示这些设备的2个截图(相同的webview内容),以便您了解我正在谈论的内容.
KindleFire: 
Galaxy Tab: 
在带有textSize LARGE的Galaxy Tab上,文本太大了,看起来很难看.因此,对于那种设备,最好在默认情况下显示NORMAL文本(并且让用户选择是否将其放大).但是我怎么知道哪个是最好的默认textSize来展示?因为NORMAL对于Galaxy Tab来说是好的,而对于Kindle Fire而言太小了,LARGE对于galaxy tab来说太大了,但对Kindle来说却是完美的.我只是在这两个设备上进行测试,但是我要支持所有平板电脑我要找到某种参数,设备中的差异才能说:好在这台设备上,因为分辨率很小我会放大/正常,而不是这个,因为它更大的结果我可以把它更大(种类).
你有没遇到过这个问题?我该如何解决?
我想在未连接互联网时从缓存加载网站.以下是我在onCreate中设置webview的方法:
browse.getSettings().setJavaScriptEnabled(true);
browse.getSettings().setPluginsEnabled(true);
browse.getSettings().setLoadWithOverviewMode(true);
browse.getSettings().setUseWideViewPort(true);
browse.getSettings().setBuiltInZoomControls(true);
browse.getSettings().setSupportZoom(true);
browse.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
browse.setScrollbarFadingEnabled(true);
browse.getSettings().setLoadsImagesAutomatically(true);
browse.getSettings().setAppCacheMaxSize(1024 * 1024 * 100);
browse.getSettings().setAppCacheEnabled(true);
if (cm.getActiveNetworkInfo().isConnected())
browse.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
else
browse.getSettings().setCacheMode(
WebSettings.LOAD_CACHE_ELSE_NETWORK);
browse.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
t.setVisibility(TextView.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
t.setVisibility(TextView.GONE);
}
});
try {
browse.loadUrl(address);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
这是我正在关注的教程,即使浏览器重新启动,我也在尝试加载以前访问过的网页.不行!请帮我.
PS:我在SO上搜索了所有相关代码,但没有一个有效.
我正在使用AsyncTask加载diva WebView,同时显示一个ProgressDialog.内容已加载并ProgressDialog显示,但它不会消失,因为执行没有进入onPostExecute().你能告诉我我做错了什么吗?
package xx.xxx.xxx;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Document;
import android.R.string;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class NewsActivity extends Activity {
private WebView wView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_main);
new LoadNews().execute("");
}
private class LoadNews extends AsyncTask<String, Integer, String> {
private ProgressDialog Dialog = new ProgressDialog(NewsActivity.this);
@Override
protected String doInBackground(String... …Run Code Online (Sandbox Code Playgroud) 我使用webview来显示youtube内容.出于某种原因,它为视频添加了一个帧.
有谁知道如何删除它?
我的代码是:
String data_html = "<iframe width=\"300\" height=\"162\" src=\"http://www.youtube.com/embed
/RbyBj-pmNwM\" frameborder=\"0\"></iframe>";
video.loadData(data_html, "text/html", null);
Run Code Online (Sandbox Code Playgroud)
这是一个我无法摆脱的白框的例子:

我在webview中打开了一个网页,并尝试使用facebook登录选项登录,但在webview中有空白屏幕失败.
on PageFinish()在WebViewClient显示页面 https://m.facebook.com/dialog/oauth?redirect_uri=http%3A%2F%2.........下加载但未能显示重定向的网址
我在用
webView.getSettings().setJavaScriptEnabled(true);
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadUrl("http://www.xyz.com/");
webView.setWebViewClient(new MyWebViewClient(this));
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.addJavascriptInterface(new WebAppInterface(this), "HTMLOUT");
Run Code Online (Sandbox Code Playgroud)
帮助它谢谢你.
我有一个Web项目(取决于WebGL),它适用于计算机,任何浏览器.现在我正在尝试将此项目作为基于Android的手机上的应用程序打开.我使用WebView来实现这一目标.我的手机(Nexus 3)有Android 4.3,而我之前在Android 5之前了解到,WebView组件不支持WebGL.在Android 5中,WebView成为可更新的独立组件,依赖于Chromium版本37(可以更新)并开始支持WebGL.因此,预计我将使用Android 4.3获得错误.
在此之后,我尝试使用另一部手机(三星Galaxy S4搭载Android 5和Chrome版本43).那么应用程序应该运行良好,但仍然在WebView上出错.我试过get.webgl.org仍然是同样的错误:
Error constructing CesiumWidget.
Visit http://get.webgl.org to verify that your web browser and hardware support WebGL. Consider trying a different web browser or updating your video drivers.
Run Code Online (Sandbox Code Playgroud)
详细的错误信息如下:
RuntimeError: The browser supports WebGL, but initialization failed.
Run Code Online (Sandbox Code Playgroud)
错误
at new RuntimeError (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:10657:19)
at new Context (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:96489:19)
at new Scene (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:120928:23)
at new CesiumWidget (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:130986:25)
at AMouseListener.Map2D.initWidget
Run Code Online (Sandbox Code Playgroud)
这似乎仍然是一个配置问题,所以我试图在Chrome上打开它而不是在WebView上但仍然是同样的错误.我在安装后在Chrome上启用了WebGL.`Firefox工作正常.我有三个问题:
似乎有什么我做错了,我该如何解决?
Android仍然不支持WebView上的WebGL,是否有任何可能的方法来打开依赖WebGL的应用程序?
有没有其他方法可以将WebGL项目作为应用程序打开.(我已阅读cordova并cocoon.js,但不能肯定是否可以通过这些来完成.)所以,如果有一个工作正常,我宁愿直接去了.
我想分享我的应用程序的内容(文本和图像),对于这个问题,我写了下面的代码:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(content) + "" +"\n\n" + "download us app from this link" + "\n\n" +"https://play.google.com/app/com.example.example");
startActivity(Intent.createChooser(sharingIntent, "select app ..."));
Run Code Online (Sandbox Code Playgroud)
但在这段代码中,我只能分享不共享图片的文字!我想分享文字和图片.
对于显示文本和图像,我使用Webview.我将图像显示在文本中webview.
我如何分享文字和图片?
我在HTML页面中有一个href链接,我链接到这样的电子邮件地址:
<p>sometext <a href="mailto:mymailadresse@gmail.com">mymailadresse@gmail.com</a></p>
Run Code Online (Sandbox Code Playgroud)
这是我的Android主要活动:
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends Activity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setDomStorageEnabled(true);
view.setWebViewClient(new MyBrowser());
view.loadUrl("file:///android_asset/www/index.html"); //try js alert
view.setWebChromeClient(new WebChromeClient()); // adding js alert
}
/**
* ATTENTION: …Run Code Online (Sandbox Code Playgroud) 它是一个带有Webview的简单WebApp,还有一个带有上载文件选项的注册页面。尝试在单击浏览按钮时打开文件选择器,但没有响应。我认为我的gradle文件中有一些问题。请帮助我调试它。这是我的代码。
这是我的项目gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序gradle
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.androidapp.myApp"
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1' …Run Code Online (Sandbox Code Playgroud)