本文整理汇总了Java中android.webkit.WebView.getSettings方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.getSettings方法的具体用法?Java WebView.getSettings怎么用?Java WebView.getSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.getSettings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initWebViewSettings
import android.webkit.WebView; //导入方法依赖的package包/类
public static void initWebViewSettings(WebView webView) {
WebSettings settings = webView.getSettings();
//这个单位是SP
settings.setDefaultFontSize(15);
settings.setJavaScriptEnabled(true); //支持js
settings.setUseWideViewPort(false); //将图片调整到适合webview的大小
settings.setSupportZoom(true); //支持缩放
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//无论是否有网络,只要本地有缓存,都使用缓存。本地没有缓存时才从网络上获取。 这里的WebView主要是用来加载图片和解析Html文本
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使超链接失效
return true;
}
});
}
示例2: initWebViewSettings
import android.webkit.WebView; //导入方法依赖的package包/类
/**
* @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);
}
示例3: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
mainIntent = getIntent();
manager = getSupportFragmentManager();
myBrowser = (WebView) findViewById(R.id.webView);
webSettings = myBrowser.getSettings();
webSettings.setJavaScriptEnabled(true);
MyDeviceAPI = Build.VERSION.SDK_INT;
// Calling async task to get display content
new RenderView().execute();
}
示例4: CustomWebViewClient
import android.webkit.WebView; //导入方法依赖的package包/类
/**
* Constructor.
* @param activity Activity to manage intents.
* @param wv <code>WebView</code> where web site will be shown.
* @param url URL address where it is hosted.
* @param urlBase URL main address.
* @param initialScale Initial zoom (0 is default).
*/
@SuppressLint("SetJavaScriptEnabled")
public CustomWebViewClient(Activity activity, WebView wv, String url, String urlBase, UrlCache urlCache, int initialScale) {
this.activity = activity;
this.wv = wv;
this.url = url;
this.urlBase = urlBase;
this.initialScale = initialScale;
this.urlCache = urlCache;
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true); // We enable Javascript by default, due to it is needed by lots of websites
wv.loadUrl(url);
wv.setInitialScale(initialScale);
}
示例5: SourceEditor
import android.webkit.WebView; //导入方法依赖的package包/类
/**
* Create source editor using given web view
*
* @param view
*/
@SuppressLint("AddJavascriptInterface")
public SourceEditor(final WebView view) {
WebSettings settings = view.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
try {
int version = Build.VERSION.SDK_INT;
if (version >= 11) {
// 这个方法在API level 11 以上才可以调用,不然会发生异常
settings.setDisplayZoomControls(false);
}
} catch (NumberFormatException e) {
}
settings.setUseWideViewPort(true);
view.addJavascriptInterface(SourceEditor.this, "SourceEditor");
this.view = view;
}
示例6: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_webview_activity);
WebView webView = findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webView.setWebViewClient(new WebViewClient());
webSettings.setJavaScriptEnabled(true);
String url = getIntent().getStringExtra("url");
if (url == null) {
url = "file:///android_res/raw/sample_form.html";
}
if (DEBUG) Log.d(TAG, "Clearing WebView data");
webView.clearHistory();
webView.clearFormData();
webView.clearCache(true);
Log.i(TAG, "Loading URL " + url);
webView.loadUrl(url);
}
示例7: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
setContentView(R.layout.activity_web);
name = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_NAME);
url = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_URL);
color = getIntent().getExtras().getInt(Common.WEBVIEW_EXTRA_COLOR);
needsLogin = getIntent().getExtras().getBoolean(Common.WEBVIEW_EXTRA_NLOGIN);
//Action bar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setNavigationBarColor(color);
getWindow().setStatusBarColor(color);
}
app = (App) getApplication();
TextView title = (TextView) findViewById(R.id.toolbar_title);
title.setText(name);
progress = (ProgressBar) findViewById(R.id.web_progressBar);
webView = (WebView) findViewById(R.id.webView);
if (savedInstanceState != null) {
progress.setVisibility(View.INVISIBLE);
webView.setVisibility(View.VISIBLE);
webView.restoreState(savedInstanceState);
}
else {
progress.setVisibility(View.VISIBLE);
webView.setWebViewClient(new WebViewClient());
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUserAgentString("IEMobile");
startControllers();
}
}
示例8: getUserAgent
import android.webkit.WebView; //导入方法依赖的package包/类
public static String getUserAgent(Context context) {
String userAgent = null;
WebView webView = new WebView(context);
WebSettings settings = webView.getSettings();
if (settings != null) {
userAgent = settings.getUserAgentString();
}
return userAgent;
}
示例9: createWebView
import android.webkit.WebView; //导入方法依赖的package包/类
private void createWebView() {
myWebView = (WebView) findViewById(R.id.webview);
myWebView.clearCache(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebViewClient = new MyWebViewClient();
myWebView.setWebViewClient(mWebViewClient);
myWebView.setWebChromeClient(new MyWebChromeClient());
// Start initial page load so WebView finishes loading proxy settings.
// Actual load of mUrl is initiated by MyWebViewClient.
}
示例10: AccountCreationWebview
import android.webkit.WebView; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
public AccountCreationWebview(BasePrefsWizard aParent, String url, OnAccountCreationDoneListener l){
parent = aParent;
creationListener = l;
webCreationPage = url;
settingsContainer = (ViewGroup) parent.findViewById(R.id.settings_container);
validationBar = (ViewGroup) parent.findViewById(R.id.validation_bar);
ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent();
parent.getLayoutInflater().inflate(R.layout.wizard_account_creation_webview, globalContainer);
webView = (WebView) globalContainer.findViewById(R.id.webview);
loadingProgressBar = (ProgressBar) globalContainer.findViewById(R.id.webview_progress);
WebSettings webSettings = webView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webSettings.setCacheMode(WebSettings.LOAD_NORMAL);
webSettings.setNeedInitialFocus(true);
webView.addJavascriptInterface(new JSInterface(), "CSipSimpleWizard");
// Adds Progress bar Support
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress < 100) {
loadingProgressBar.setVisibility(View.VISIBLE);
loadingProgressBar.setProgress(progress);
}else {
loadingProgressBar.setVisibility(View.GONE);
}
}
});
}
示例11: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
listeners = new ArrayList<>();
progressListeners = new ArrayList<>();
webView = new WebView(this);
webView.setWebViewClient(new WebClient(this));
webView.setWebChromeClient(new ChromeClient(this));
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadsImagesAutomatically(false);
webSettings.setUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0");
}
示例12: onViewCreated
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
WebView webView = (WebView) view.findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
settings.setAllowUniversalAccessFromFileURLs(true);
}
settings.setBuiltInZoomControls(true);
//webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(GOOGLE_DRIVE_LINK2 + WEB_PATH_TO_PDF);
}
示例13: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
myWebView.addJavascriptInterface(new WebAppInterface(WebviewActivity.this), "Android");
myWebView.setWebViewClient(new MyWebViewClient());
// hosted site url
myWebView.loadUrl("http://cicradon.000webhostapp.com/");
}
示例14: init
import android.webkit.WebView; //导入方法依赖的package包/类
/**
* 系统初始化
*
* @param context
*/
public static void init(Context context)
{
if (CDK.getInstance().getContext() != null)
{
return;
}
Context application = context.getApplicationContext();
// 用于获取浏览器代理
WebView webview = new WebView(context);
webview.layout(0, 0, 0, 0);
WebSettings webSettings = webview.getSettings();
ApplicationInfo applicationInfo = context.getApplicationInfo();
VersionInfo versionInfo = ManifestTools.getVersionInfo(application);
String userAgent = webSettings.getUserAgentString();
// Structure the CDKContext.
CDKContext cdkContext = new CDKContext(application.getPackageName());
//clientInfo.setAppicon(R.drawable.ic_launcher);
cdkContext.setAppicon(applicationInfo.icon);
cdkContext.setAppname(ManifestTools.getApplicationLable(application));
cdkContext.setDeviceType(CDKConfig.Device.PHONE);
cdkContext.setAlias(android.os.Build.MODEL);
cdkContext.setAndroidSdkVersion(android.os.Build.VERSION.SDK_INT);
cdkContext.setMac(DeviceInfoManager.getMacAddress(application));
// Webkit user-agent
cdkContext.setUserAgent(userAgent);
if (versionInfo != null)
{
cdkContext.setAppVersionCode(versionInfo.getVersionCode());
cdkContext.setAppVersionName(versionInfo.getVersionName());
}
// FIXME: Take attention...
cdkContext.addFlags(CDKContext.FLAG_DEBUG | CDKContext.FLAG_RELEASE);
// cdkContext.addFlags(CDKContext.FLAG_DEBUG);
// TODO: 广告
CDKConfig config = new CDKConfig.Builder(application)
.cdkContext(cdkContext)
.hasAdBanner(false) // 显示积分Banner
.hasAdPointsWall(true) // 显示积分墙
.build();
CDK.getInstance().init(config);
}
示例15: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
Intent in = getIntent();
web = in.getStringExtra("web");
if (TextUtils.isEmpty(web)) {
Toast.makeText(this, "地址为空", Toast.LENGTH_SHORT).show();
} else {
WebView webView = (WebView) findViewById(R.id.web);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;// 返回false
}
});
WebSettings webSettings = webView.getSettings();
// 让WebView能够执行javaScript
webSettings.setJavaScriptEnabled(true);
// 让JavaScript可以自动打开windows
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
// // 设置缓存
// webSettings.setAppCacheEnabled(true);
// // 设置缓存模式,一共有四种模式
// webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
// // 设置缓存路径
// webSettings.setAppCachePath("/storage/emulated/0/Android/data/com.easyar.buddha/files");
// 支持缩放(适配到当前屏幕)
webSettings.setSupportZoom(true);
// 将图片调整到合适的大小
webSettings.setUseWideViewPort(true);
// 支持内容重新布局,一共有四种方式
// 默认的是NARROW_COLUMNS
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
// 设置可以被显示的屏幕控制
webSettings.setDisplayZoomControls(true);
// 设置默认字体大小
webSettings.setDefaultFontSize(12);
webView.loadUrl(web);
}
}