Java 类android.webkit.WebSettings 实例源码
项目:ShaddockVideoPlayer
文件:NWebView.java
public void openCache(String cacheDirPath){
//设置缓存模式
mWebSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
// 开启DOM storage API 功能
mWebSettings.setDomStorageEnabled(true);
// 开启database storage API功能
mWebSettings.setDatabaseEnabled(true);
// 设置数据库缓存路径
mWebSettings.setAppCachePath(cacheDirPath);
mWebSettings.setAppCacheEnabled(true);
}
项目:QuranAndroid
文件:AboutActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
getSupportActionBar().setTitle(getString(R.string.about));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
progressBar = (ProgressBar) findViewById(R.id.progress);
progressBar.getIndeterminateDrawable()
.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
info_web = (WebView) findViewById(R.id.webview_company_info);
info_web.setBackgroundColor(Color.TRANSPARENT);
info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
info_web.setWebViewClient(new myWebClient());
info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
info_web.getSettings().setJavaScriptEnabled(true);
String infoText = getString(R.string.company_info_web);
info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);
}
项目:AgentWeb
文件:AgentWebUtils.java
static void clearWebViewAllCache(Context context, WebView webView) {
try {
AgentWebConfig.removeAllCookies(null);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
context.deleteDatabase("webviewCache.db");
context.deleteDatabase("webview.db");
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
clearCacheFolder(new File(AgentWebConfig.getCachePath(context)), 0);
} catch (Exception ignore) {
//ignore.printStackTrace();
if (AgentWebConfig.DEBUG)
ignore.printStackTrace();
}
}
项目:Mobike
文件:TripDetailActivity.java
private void initWebView() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
/*使webview能够加载图片*/
webSettings.setBlockNetworkImage(false);
webSettings.setAppCacheEnabled(true);
mDialog=new SpotsDialog(this);
mDialog.show();
mWebView.loadUrl(mMessage.getClickUrl());
// mWebAppInterface = new WebAppInterface(this);
// mWebView.addJavascriptInterface(mWebAppInterface, "appInterface");
mWebView.setWebViewClient(new MyWebChromeC());
mWebView.setWebChromeClient(new WebChromeClient(){
});
}
项目:GitHub
文件:CustomWebView.java
@SuppressLint("SetJavaScriptEnabled")
private void init(Context context) {
// 顶部显示的进度条
mProgressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
mProgressBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 7, 0, 0));
Drawable drawable = context.getResources().getDrawable(R.drawable.layer_web_progress_bar);
mProgressBar.setProgressDrawable(drawable);
addView(mProgressBar);
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true); // 是能放大缩小
webSettings.setUseWideViewPort(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webSettings.setLoadWithOverviewMode(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);//隐藏
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
//webSettings.setUseWideViewPort(true);
this.setWebViewClient(mWebViewClientBase);
this.setWebChromeClient(mWebChromeClientBase);
setDownloadListener(new DownloadListener());
this.onResume();
}
项目:GitHub
文件:GoodsInfoActivity.java
private void setWebView(String product_id) {
if (product_id != null) {
//http://192.168.51.104:8080/atguigu/json/GOODSINFO_URL.json2691
// wbGoodInfoMore.loadUrl(Constants.GOODSINFO_URL + product_id);
wbGoodInfoMore.loadUrl("http://www.atguigu.com");
//覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开
wbGoodInfoMore.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
view.loadUrl(url);
return true;
}
});
//启用支持javascript
WebSettings settings = wbGoodInfoMore.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
//优先使用缓存
wbGoodInfoMore.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
}
项目:touchtestweb-android
文件:PrivacyPolicyActivity.java
@Override
@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_privacy_policy);
final WebView privacyPolicyWebView = (WebView)findViewById(R.id.privacypolicy);
privacyPolicyWebView.setVisibility(View.VISIBLE);
privacyPolicyWebView.getSettings().setJavaScriptEnabled(true);
privacyPolicyWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
privacyPolicyWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
privacyPolicyWebView.setWebViewClient(new WebViewClient() { });
privacyPolicyWebView.resumeTimers();
privacyPolicyWebView.loadUrl("http://www.soasta.com/privacy-policy");
}
项目:FaceRecognition
文件:Main2Activity.java
private void preSetting(){
//加载服务器上的页面
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBlockNetworkImage(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(
WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
// TODO Auto-generated method stub
// handler.cancel();// Android默认的处理方式
handler.proceed();// 接受所有网站的证书
// handleMessage(Message msg);// 进行其他处理
}
});
//加载本地中的html
//myWebView.loadUrl("file:///android_asset/www/test2.html");
//加上下面这段代码可以使网页中的链接不以浏览器的方式打开
mWebView.setWebViewClient(new WebViewClient());
//允许使用javascript
mWebView.getSettings().setJavaScriptEnabled(true);
}
项目:FriendBook
文件:AppRouter.java
/**
* @param webView
*/
@SuppressLint("SetJavaScriptEnabled")
public static void initWebViewSettings(WebView webView) {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webSettings.setDefaultFontSize(15);
//设置缓存
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setAppCacheEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCachePath(AppConfig.WEB_CACHE_PATH);
}
项目:nfkita-mobile
文件:ReadArticleActivity.java
private void loadData() {
Picasso.with(this).load(getIntent("thumbnail")).into(imgCover);
txtWriter.setText(getIntent("writer"));
txtDate.setText(getIntent("date"));
webViewContent.setScrollContainer(false);
webViewContent.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webViewContent.loadData(WebViewContent.clean(getContent()), "text/html; charset=utf-8", "utf-8");
}
项目:QuranAndroid
文件:AboutActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
getSupportActionBar().setTitle(getString(R.string.about));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
progressBar = (ProgressBar) findViewById(R.id.progress);
progressBar.getIndeterminateDrawable()
.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
info_web = (WebView) findViewById(R.id.webview_company_info);
info_web.setBackgroundColor(Color.TRANSPARENT);
info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
info_web.setWebViewClient(new myWebClient());
info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
info_web.getSettings().setJavaScriptEnabled(true);
String infoText = getString(R.string.company_info_web);
info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);
}
项目:framer-android-wrapper
文件:MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setAllowFileAccessFromFileURLs(true);
settings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavascriptHandler(this, webView), "JavascriptHandler");
webView.loadUrl("file:///android_asset/Sample.framer/index.html");
}
项目:mvvm-template
文件:PrettifyWebView.java
public void loadImage(@NonNull String url, boolean isSvg) {
WebSettings settings = getSettings();
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
String html;
if (isSvg) {
html = url;
} else {
html = "<html><head><style>img{display: inline; height: auto; max-width: 100%;}</style></head><body>" +
"<img src=\"" + url + "\"/></body></html>";
}
Logger.e(html);
loadData(html, "text/html", null);
}
项目:LQRWeChat
文件:WebViewActivity.java
@Override
public void initView() {
mIbToolbarMore.setVisibility(View.VISIBLE);
//设置webView
WebSettings settings = mWebView.getSettings();
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumLogicalFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(WebSettings.TextSize.NORMAL);
mWebView.setVerticalScrollbarOverlay(true);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl(mUrl);
setToolbarTitle(TextUtils.isEmpty(mTitle) ? mWebView.getTitle() : mTitle);
}
项目:LikeGank
文件:WebViewActivity.java
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void initViews() {
setTitle(getIntent().getStringExtra(EXTRA_TITLE));
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setAppCacheEnabled(true);
settings.setSupportZoom(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mUrl = getIntent().getStringExtra(EXTRA_URL);
mWebView.loadUrl(mUrl);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
}
项目:boohee_v5.6
文件:i.java
protected RegisterView a() {
RegisterView registerView = new RegisterView(this.activity);
registerView.c().getChildAt(registerView.c().getChildCount() - 1).setVisibility(8);
registerView.a().setOnClickListener(new j(this));
this.e = registerView.b();
WebSettings settings = this.e.getSettings();
settings.setBuiltInZoomControls(true);
settings.setJavaScriptEnabled(true);
settings.setCacheMode(1);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDatabasePath(this.activity.getDir("database", 0).getPath());
this.e.setVerticalScrollBarEnabled(false);
this.e.setHorizontalScrollBarEnabled(false);
this.e.setWebViewClient(new l(this));
return registerView;
}
项目:planetcon
文件:HelpActivity.java
private void setTextSize() {
WebSettings webSettings = mHelpView.getSettings();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int textSize = SettingsActivity.getNumericPref(prefs, SettingsActivity.KEY_TEXT_SIZE, SettingsActivity.DEF_TEXT_SIZE);
if (textSize >= 16) {
webSettings.setDefaultFontSize(16 + FONT_OFFSET);
} else if (textSize >= 14) {
webSettings.setDefaultFontSize(14 + FONT_OFFSET);
} else if (textSize >= 12) {
webSettings.setDefaultFontSize(12 + FONT_OFFSET);
} else if (textSize >= 10) {
webSettings.setDefaultFontSize(10 + FONT_OFFSET);
} else if (textSize >= 8) {
webSettings.setDefaultFontSize(8 + FONT_OFFSET);
} else {
webSettings.setDefaultFontSize(16);
}
}
项目:Hotspot-master-devp
文件:CustomWebView.java
private void initViews() {
LayoutInflater.from(getContext()).inflate(R.layout.view_webview, this, true);
mWebView = (MyWebView) findViewById(R.id.webview);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView.setWebViewClient(new MyClient());
// mWebView.setWebChromeClient(new MyWebChromeClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
webSettings.setBlockNetworkImage(true);
mWebView.setOnScrollBottomListener(this);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
}
项目:GracefulMovies
文件:WebActivity.java
private void initWebView(String url) {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setGeolocationEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDisplayZoomControls(false);
if (Build.VERSION.SDK_INT >= 21) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.loadUrl(url);
}
项目:ZhaZhaShop
文件:WebViewActivity.java
private void setupWebView() {
WebSettings settings = mWvWebview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(false);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setDomStorageEnabled(true);
WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(String.valueOf(request.getUrl()));
return true;
}
};
mWvWebview.setWebViewClient(webViewClient);
}
项目:WebPager
文件:PagerWebView.java
private void init() {
final WebSettings setting = getSettings();
setting.setJavaScriptEnabled(true);
setting.setSupportZoom(false);
setting.setSupportMultipleWindows(true);
setting.setSupportZoom(false);
setting.setBuiltInZoomControls(false);
setting.setSupportMultipleWindows(true);
setting.setJavaScriptCanOpenWindowsAutomatically(true);
setting.setDomStorageEnabled(true);
setting.setNeedInitialFocus(false);
setting.setGeolocationEnabled(true);
setting.setAllowFileAccess(true);
setFocusable(true);
setFocusableInTouchMode(true);
}
项目:letv
文件:PKDialog.java
@SuppressLint({"SetJavaScriptEnabled"})
private void initViews() {
this.mWebView.setVerticalScrollBarEnabled(false);
this.mWebView.setHorizontalScrollBarEnabled(false);
this.mWebView.setWebViewClient(new FbWebViewClient());
this.mWebView.setWebChromeClient(this.mChromeClient);
this.mWebView.clearFormData();
WebSettings settings = this.mWebView.getSettings();
settings.setSavePassword(false);
settings.setSaveFormData(false);
settings.setCacheMode(-1);
settings.setNeedInitialFocus(false);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setJavaScriptEnabled(true);
if (!(this.mWeakContext == null || this.mWeakContext.get() == null)) {
settings.setDatabaseEnabled(true);
settings.setDatabasePath(((Context) this.mWeakContext.get()).getApplicationContext().getDir("databases", 0).getPath());
}
settings.setDomStorageEnabled(true);
this.jsBridge.a(new JsListener(), "sdk_js_if");
this.mWebView.clearView();
this.mWebView.loadUrl(this.mUrl);
this.mWebView.getSettings().setSavePassword(false);
}
项目:lqrwechatrongcloud
文件:WebViewActivity.java
@Override
public void initView() {
mIbToolbarMore.setVisibility(View.VISIBLE);
//设置webView
WebSettings settings = mWebView.getSettings();
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumLogicalFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(WebSettings.TextSize.NORMAL);
mWebView.setVerticalScrollbarOverlay(true);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl(mUrl);
setToolbarTitle(TextUtils.isEmpty(mTitle) ? mWebView.getTitle() : mTitle);
}
项目:CacheWebView
文件:CacheWebView.java
private void setCachePath(){
File cacheFile = new File(this.getContext().getCacheDir(),CACHE_NAME);
String path = cacheFile.getAbsolutePath();
mAppCachePath = path;
File file = new File(path);
if (!file.exists()){
file.mkdirs();
}
WebSettings webSettings = this.getSettings();
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDatabasePath(path);
}
项目:Hubs
文件:HubsWebView.java
@SuppressLint("SetJavaScriptEnabled")
private void init() {
final WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
mWebViewClient = new HubsWebViewClient();
setWebViewClient(mWebViewClient);
}
项目:AndroidTVCursor
文件:MainActivity.java
@SuppressLint("SetJavaScriptEnabled")
private void initWebView() {
webView = findViewById(R.id.webView);
WebSettings webSetting = webView.getSettings();
webSetting.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
// 这个链接可以测试鼠标拖动的轨迹,通过画线的痕迹
// webView.loadUrl("https://muro.deviantart.com/");
webView.loadUrl("http://www.baidu.com");
webView.requestFocus();
}
项目:phonk
文件:PWebView.java
public PWebView(AppRunner appRunner) {
super(appRunner.getAppContext());
mAppRunner = appRunner;
styler = new Styler(appRunner, this, props);
// styler.apply();
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
this.setFocusable(true);
this.setFocusableInTouchMode(true);
this.clearCache(false);
this.setBackgroundColor(0x00000000);
this.requestFocus(View.FOCUS_DOWN);
this.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});
WebViewClient webViewClient = new CustomWebViewClient();
this.setWebViewClient(webViewClient);
this.addJavascriptInterface(mAppRunner.pApp, "app");
}
项目:GitHub
文件:ViewStoryActivity.java
private void setupWebView() {
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) mProgressContainer.setVisibility(ProgressBar.GONE);
}
});
mWebView.setWebViewClient(new ProgressWebViewClient());
mWebView.setInitialScale(1);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDisplayZoomControls(true);
mWebView.getSettings().setLoadsImagesAutomatically(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
if (DataUtils.isNetworkAvailable(this)) {
showHideOfflineLayout(false);
if (mPost.postType == Post.PostType.STORY) {
String strippedUrl = mPost.url.split("\\?")[0].split("#")[0];
mWebView.loadUrl(strippedUrl.endsWith(KEY_PDF) ? URL_GOOGLE_DOCS + mPost.url : mPost.url);
} else {
mWebView.loadUrl(mPost.url);
}
} else {
showHideOfflineLayout(true);
}
}
项目:GitHub
文件:InnerBrowserFragment.java
private void initWebViewSettings(WebView webView) {
//能够和js交互
webView.getSettings().setJavaScriptEnabled(true);
//缩放,设置为不能缩放可以防止页面上出现放大和缩小的图标
webView.getSettings().setBuiltInZoomControls(false);
//缓存
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//开启DOM storage API功能
webView.getSettings().setDomStorageEnabled(true);
//开启application Cache功能
webView.getSettings().setAppCacheEnabled(false);
}
项目:OSchina_resources_android
文件:BrowserFragment.java
/**
* 初始化浏览器设置信息
*/
private void initWebView() {
cookie = CookieManager.getInstance();
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true); // 启用支持javascript
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);// 优先使用缓存
webSettings.setAllowFileAccess(true);// 可以访问文件
webSettings.setBuiltInZoomControls(true);// 支持缩放
if (android.os.Build.VERSION.SDK_INT >= 11) {
webSettings.setPluginState(PluginState.ON);
webSettings.setDisplayZoomControls(false);// 支持缩放
}
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(new MyWebChromeClient());
}
项目:ZhidaoDaily-android
文件:DetailActivity.java
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled", "AddJavascriptInterface"})
private void initWebView() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
mWebView.addJavascriptInterface(new JsInterface(this), "imgClickListener");
mWebView.addJavascriptInterface(new JsInterface(this), "comjs");
mWebView.setWebViewClient(new BaseWebViewClient());
}
项目:touchtestweb-android
文件:MainActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private String getDefaultUserAgent(Context context)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
// SDK version 17 and greater support new method to query for user-agent
return WebSettings.getDefaultUserAgent(context);
}
// Older SDK versions can use the older way of retrieving the user agent
return System.getProperty(SYSTEM_USER_AGENT_PROPERTY_KEY);
}
项目:Pluto-Android
文件:BlogFragment.java
private void initUI() {
//去除长按菜单
webView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
// 设置WebView属性,能够执行Javascript脚本
WebSettings settings = webView.getSettings();
if (settings != null) {
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
}
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
webView.setWebChromeClient(new WebChromeClient());
if (type == 1) {
webView.loadUrl("https://m8en.com");
} else {
webView.loadUrl("http://www.jianshu.com/u/a5016e728b89");
}
}
项目:LianXiZhihu
文件:InnerBrowserFragment.java
private void initWebViewSettings(WebView webView) {
//能够和js交互
webView.getSettings().setJavaScriptEnabled(true);
//缩放,设置为不能缩放可以防止页面上出现放大和缩小的图标
webView.getSettings().setBuiltInZoomControls(false);
//缓存
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//开启DOM storage API功能
webView.getSettings().setDomStorageEnabled(true);
//开启application Cache功能
webView.getSettings().setAppCacheEnabled(false);
}
项目:dcs-sdk-java
文件:BaseWebView.java
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void init(Context context) {
this.setVerticalScrollBarEnabled(false);
this.setHorizontalScrollBarEnabled(false);
if (Build.VERSION.SDK_INT < 19) {
removeJavascriptInterface("searchBoxJavaBridge_");
}
WebSettings localWebSettings = this.getSettings();
try {
// 禁用file协议,http://www.tuicool.com/articles/Q36ZfuF, 防止Android WebView File域攻击
localWebSettings.setAllowFileAccess(false);
localWebSettings.setSupportZoom(false);
localWebSettings.setBuiltInZoomControls(false);
localWebSettings.setUseWideViewPort(true);
localWebSettings.setDomStorageEnabled(true);
localWebSettings.setLoadWithOverviewMode(true);
localWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
localWebSettings.setPluginState(PluginState.ON);
// 启用数据库
localWebSettings.setDatabaseEnabled(true);
// 设置定位的数据库路径
String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
localWebSettings.setGeolocationDatabasePath(dir);
localWebSettings.setGeolocationEnabled(true);
localWebSettings.setJavaScriptEnabled(true);
localWebSettings.setSavePassword(false);
String agent = localWebSettings.getUserAgentString();
localWebSettings.setUserAgentString(agent);
// setCookie(context, ".baidu.com", bdussCookie);
} catch (Exception e1) {
e1.printStackTrace();
}
this.setWebViewClient(new BridgeWebViewClient());
}
项目:order-by-android
文件:ViewNoticia.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_noticia);
//Pega a notícia passada pela ActivityPrincipal
mNoticia = (Noticia)getIntent().getExtras().get("noticia");
//Obtem da View
mToolbar = (Toolbar) findViewById(R.id.tb_noticias);
mToolbar.setTitle(mNoticia.getTitulo());
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
//Obtem da View
mImageView = (ImageView) findViewById(R.id.iv_noticias);
//Carrega a imagem com a biblioteca Picasso
Picasso.with(this).load(Uri.parse(Utils.getUrlApiThumbnail(this).replace("$tipo", "noticias").replace("$id", String.valueOf(mNoticia.getId()))+"&thumb=false")).placeholder(R.drawable.no_avatar).into(mImageView);
//Obtem da View
mWebView = (WebView) findViewById(R.id.web_noticias);
//Carrega o conteúdo
mWebView.loadDataWithBaseURL("file:///android_asset/","<link rel=\"stylesheet\" type=\"text/css\" href=\"estilo.css\" />"+mNoticia.getConteudo(),"text/html", "UTF-8", null);
//Permite Javascript e outros fatores
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowContentAccess(true);
WebSettings webSettings = mWebView.getSettings();
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setUseWideViewPort(true);
mWebView.setWebChromeClient(new WebChromeClient() {});
}
项目:webview-restore
文件:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCachePath(getCacheDir().getPath());
webView.getSettings().setAppCacheEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webView.onPageFinished(view, url);
}
});
webView.addJavascriptInterface(new JSInteraction(), "contact");
if (savedInstanceState != null) {
webView.restoreState(savedInstanceState);
} else {
webView.loadUrl(URL_LOCAL);
}
}
项目:li-android-sdk-core
文件:LiLoginActivity.java
@Override
public void onCreate(Bundle savedInstanceBundle) {
super.onCreate(savedInstanceBundle);
setContentView(R.layout.li_login_activity);
Intent intent = getIntent();
Toolbar toolbar = (Toolbar) findViewById(R.id.li_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
service = new LiAuthServiceImpl(this);
webViewOauth = (WebView) findViewById(R.id.li_web_oauth);
progBar = (ProgressBar) findViewById(R.id.li_login_page_prog_bar);
loginInProgTxt = (TextView) findViewById(R.id.li_login_in_prog_txt);
String authUrl = intent.getData().toString();
progBar.setVisibility(View.VISIBLE);
webViewOauth.setVisibility(View.INVISIBLE);
loginInProgTxt.setText(getString(R.string.li_openingLoginPage));
loginInProgTxt.setVisibility(View.VISIBLE);
isAccessTokenSaved = false;
webViewOauth.clearHistory();
webViewOauth.clearFormData();
webViewOauth.clearCache(true);
setTitle(authUrl);
//set the web client
webViewOauth.setWebViewClient(new LoginWebViewClient());
webViewOauth.setWebChromeClient(new LoginWebChromeClient());
//activates JavaScript (just in case)
WebSettings webSettings = webViewOauth.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAppCacheEnabled(false);
//load the url of the oAuth login page
webViewOauth.loadUrl(authUrl);
}
项目:kolibri-android
文件:KolibriWebView.java
private void init() {
if (!isInEditMode()) {
final InternalWebViewClient internalWebViewClient = new InternalWebViewClient();
final InternalChromeClient internalChromeClient = new InternalChromeClient();
webClients = new ArrayList<>();
webChromeClients = new ArrayList<>();
super.setWebViewClient(internalWebViewClient);
super.setWebChromeClient(internalChromeClient);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
getSettings().setJavaScriptEnabled(true);
getSettings().setAppCacheEnabled(true);
getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
getSettings().setDomStorageEnabled(true);
getSettings().setUserAgentString(UA_STRING_PREFIX + " " + getSettings().getUserAgentString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// chromium, enable hardware acceleration
setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
// older android version, disable hardware acceleration
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
clearHistory = false;
}
}
项目:YFHR_Android_App
文件:Knowyour30_webview.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view= inflater.inflate(R.layout.fragment_knowyour30_webview, container, false);
web=(WebView)view.findViewById(R.id.web_View);
WebSettings webs =web.getSettings();
webs.setJavaScriptEnabled(true);
web.loadUrl(myUrl);
web.setWebViewClient(new myWebViewClient());
return view;
}