/** * 初始化 * * @param web_view * @param activity * @return */ public static WebView WebSettingInit(WebView web_view, final Activity activity) { WebSettings ws = web_view.getSettings(); ws.setJavaScriptEnabled(true); // 支持js ws.setBuiltInZoomControls(false); // 支持缩放按钮 ws.setUseWideViewPort(true); // 设置此属性,可任意比例缩放 将图片调整到适合webview的大小 ws.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); ws.setSupportZoom(false); // 支持缩放 // 设置 缓存模式 ws.setCacheMode(WebSettings.LOAD_NO_CACHE); // 关闭webview中缓存 web_view.clearCache(true); web_view.setTag(true); // 开启 DOM storage API 功能 ws.setDomStorageEnabled(true); ws.setRenderPriority(RenderPriority.HIGH); // 开启 database storage API 功能 ws.setDatabaseEnabled(false); web_view.setWebChromeClient( new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); return web_view; }
/** * @author lijing * @time 2014-7-22 下午3:31:38 */ private void initInfo() { webview = (WebView) layout.findViewById(R.id.webview); WebSettings webSettings = webview.getSettings(); // webView: 类WebView的实例 webSettings.setJavaScriptEnabled(true); webSettings.setUseWideViewPort(true); webSettings.setSupportZoom(true); // webSettings.setBuiltInZoomControls(true); webSettings.setLoadWithOverviewMode(true); webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // 就是这句 pb = (ProgressBar) layout.findViewById(R.id.pb); pb.setMax(100); if (TextUtils.isEmpty(url)) return; webview.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webview.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { pb.setProgress(newProgress); if (newProgress == 100) { pb.setVisibility(View.GONE); } super.onProgressChanged(view, newProgress); } }); webview.loadUrl(url); }
@SuppressLint({"NewApi", "SetJavaScriptEnabled"}) private void loadWebView() { // 实例化WebView对象 // webview = new MyWebView(WebViewActivity.this); LogUtil.i(TAG, "loadWebView===实例化WebView==="); webview = (MyWebView) findViewById(R.id.id_webview); new MobclickAgentJSInterface(this, webview); WebSettings webSettings = webview.getSettings(); // 设置WebView属性,能够执行Javascript脚本 webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // webSettings.setUseWideViewPort(true); // 关键点 webSettings.setLoadWithOverviewMode(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCacheMaxSize(8 * 1024 * 1024); // 8MB // webSettings.setAppCachePath(Constants.WEBVIEW_CACHE_DIR ); String appCacheDir = this.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath(); webSettings.setAppCachePath(appCacheDir); webSettings.setAllowFileAccess(true); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // js调用安卓方法 webview.addJavascriptInterface(this, "RedirectListner"); }
public void initWebview(WebView paramWebView) { WebSettings localWebSettings = paramWebView.getSettings(); localWebSettings.setJavaScriptEnabled(true); if (Build.VERSION.SDK_INT > 7) localWebSettings.setPluginState(WebSettings.PluginState.ON); localWebSettings.setSupportZoom(true); localWebSettings.setBuiltInZoomControls(true); localWebSettings.setAllowFileAccess(true); localWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); localWebSettings.setUseWideViewPort(true); if (Build.VERSION.SDK_INT >= 8) { localWebSettings.setLoadWithOverviewMode(true); localWebSettings.setDatabaseEnabled(true); localWebSettings.setDomStorageEnabled(true); localWebSettings.setGeolocationEnabled(true); localWebSettings.setAppCacheEnabled(true); } if (Build.VERSION.SDK_INT >= 11) ; try { Class[] arrayOfClass = new Class[1]; arrayOfClass[0] = Boolean.TYPE; Method localMethod = WebSettings.class.getDeclaredMethod("setDisplayZoomControls", arrayOfClass); localMethod.setAccessible(true); Object[] arrayOfObject = new Object[1]; arrayOfObject[0] = Boolean.valueOf(false); localMethod.invoke(localWebSettings, arrayOfObject); return; } catch (Exception localException) { com.taobao.newxp.common.Log.e(ExchangeConstants.LOG_TAG, "", localException); } }
private void setData() { webView.setVisibility(View.VISIBLE); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setDefaultFontSize(16); webView.requestFocusFromTouch(); // 支持获取手势焦点 webView.setWebViewClient( new WebViewClient() { // 打开网页时不调用系统浏览器, 而是在本WebView中显示 @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webView.setWebChromeClient( new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); webView.loadDataWithBaseURL(null, CONTENT, "text/html", "UTF-8", null); dialog.cancel(); }
@TargetApi(8) private void load() { final String uri = getPath(); final WebSettings settings = wv.getSettings(); if (uri.endsWith(".swf") && ActivityUtil.isGreaterThan_2_1()) // android 2.2 { wv.setWebChromeClient(new WebChromeClient()); // settings.setPluginState(PluginState.ON); wv.loadUrl(uri); getSupportActionBar().setTitle("查看视频"); } else { // images settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setUseWideViewPort(true); if (ActivityUtil.isGreaterThan_2_1()) settings.setLoadWithOverviewMode(true); // settings.setUserAgentString(IPHONE_UA); wv.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub return false; } }); wv.loadUrl(uri); getSupportActionBar().setTitle("查看图片"); } }
@Override public void onCreate(Bundle savedInstanceState) { Log.d(); super.onCreate(savedInstanceState); setHasOptionsMenu(true); mBrowser = this; mVizWebViewClient = new VizWebViewClient(this); mWebChromeClient = new VizWebChromeClient(this); mVizWebView = new WebView(getActivity()); // get attributes? mVizWebView.setWebViewClient(mVizWebViewClient); mVizWebView.setWebChromeClient(mWebChromeClient); if (savedInstanceState != null) { Log.d("restoring web view state"); mVizWebView.restoreState(savedInstanceState); } WebSettings s = mVizWebView.getSettings(); s.setJavaScriptEnabled(true); s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); s.setBuiltInZoomControls(true); s.setUseWideViewPort(true); s.setLoadWithOverviewMode(true); s.setSaveFormData(true); mVizWebView.setId(61377); // PhoneWindow complained about no id (focus couldn't be saved) // Loading homepage here results in an exception on ICS, not sure why. // Update: post-poning until onCreatingView doesn't entirely fix the // issue either. // mVizWebView.loadUrl(defaultURL); }
/** * Convenience method to set some generic defaults for a given WebView * * @param webView */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setUpWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); // Enable Javascript settings.setJavaScriptEnabled(true); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); // Enable pinch to zoom without the zoom buttons settings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ settings.setDisplayZoomControls(false); } // Enable remote debugging via chrome://inspect if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } // We set the WebViewClient to ensure links are consumed by the WebView rather // than passed to a browser if it can webView.setWebViewClient(new WebViewClient()); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fun_everyday, container, false); menu = (ImageButton) view.findViewById(R.id.btn_header_left); menu.setOnClickListener(this); TextView headText = (TextView) view.findViewById(R.id.title_header_mid); headText.setText(R.string.text_menu_story); String url = "http://www.molegegu.com/im/webview.htm"; mWebView = (WebView) view.findViewById(R.id.sub_xeb_webview); mWebView.loadUrl(url); mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); mProgressBar = (ProgressBar) view.findViewById(R.id.loadProgress); mWebView = (WebView) view.findViewById(R.id.sub_xeb_webview); mWebView.loadUrl(url); mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); // set the webview WebSettings settings = mWebView.getSettings(); settings.setSupportZoom(true); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setDefaultTextEncodingName("GBK"); settings.setTextSize(TextSize.NORMAL); settings.setJavaScriptEnabled(true); settings.setUseWideViewPort(true); mWebView.setInitialScale(80); mWebView.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress > 0 && newProgress < 100) { mProgressBar.setVisibility(View.VISIBLE); mProgressBar.setProgress(newProgress); } else if (newProgress == 100) { mProgressBar.setVisibility(View.GONE); } } }); mWebView.requestFocusFromTouch(); return view; }
@SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); Bundle bundle = getIntent().getExtras(); String url = bundle.getString("url"); String title = bundle.getString("title"); current_url = url; WebViewActivity.this.setTitle(title); final Context myApp = this; setContentView(R.layout.activity_webview); CookieSyncManager.createInstance(myApp); WebSettings settings = getWebView().getSettings(); settings.setJavaScriptEnabled(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); // settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); final WebView webview = (WebView) getWebView(); webview.setWebViewClient(new MyWebViewClient()); webview.setWebChromeClient(new MyWebChromeClient()); webview.loadUrl(url); }
private void initViewer() { settings.setLoadsImagesAutomatically(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setLightTouchEnabled(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); viewer.setInitialScale(0); viewer.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); viewer.setHorizontalScrollBarEnabled(false); viewer.setVerticalScrollBarEnabled(false); viewer.setBackgroundColor(0x000000); viewer.clearCache(true); viewer.setFocusable(false); viewer.setWebViewClient( new WebViewClient() { @Override public void onPageFinished(WebView view, String url) {} @Override public void onReceivedError( WebView view, int errorCode, String description, String failingUrl) {} @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); mWebView = (WebView) findViewById(R.id.webview); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (URLUtil.isNetworkUrl(url)) { if (mLoadingProgressBar != null) { mLoadingProgressBar.setVisibility(View.VISIBLE); mLoadingProgressBar.startAnimation( AnimationUtils.loadAnimation(WebViewActivity.this, R.anim.abc_fade_in)); } view.loadUrl(url); } else { // Otherwise allow the OS to handle things like tel, mailto, etc. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); } return true; } @Override public void onPageFinished(WebView view, String url) { if (mLoadingProgressBar != null) { mLoadingProgressBar.setVisibility(View.GONE); mLoadingProgressBar.startAnimation( AnimationUtils.loadAnimation(WebViewActivity.this, R.anim.abc_fade_out)); } } }); Intent intent = getIntent(); if (intent != null) { String url = intent.getStringExtra(DATA_URL); if (URLUtil.isNetworkUrl(url)) { mWebView.loadUrl(url); } String title = intent.getStringExtra(DATA_TITLE); if (!TextUtils.isEmpty(title)) { setTitle(title); } } mLoadingProgressBar = getToolbar().findViewById(R.id.toolbar_progress_bar); mLoadingProgressBar.setVisibility(View.VISIBLE); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null) .show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); // WebView mwebView = (WebView) findViewById(R.id.myWebView); WebSettings webSettings = mwebView.getSettings(); webSettings.setJavaScriptEnabled(true); // improve webView performance mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); mwebView.getSettings().setAppCacheEnabled(true); mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webSettings.setDomStorageEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setEnableSmoothTransition(true); mwebView.loadUrl("http://www.newsweek.com"); // force links open in webview only mwebView.setWebViewClient(new MyWebviewClient()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); // -------------------------------TabView toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); // -------------------------------------- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); // WebView mwebView = (WebView) findViewById(R.id.myWebView); WebSettings webSettings = mwebView.getSettings(); webSettings.setJavaScriptEnabled(true); // improve webView performance mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); mwebView.getSettings().setAppCacheEnabled(true); mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webSettings.setDomStorageEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setEnableSmoothTransition(true); mwebView.loadUrl("http://www.newsweek.com"); // force links open in webview only mwebView.setWebViewClient(new MyWebviewClient()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_innerweb); ButterKnife.bind(this); StatusBarHelper.setStatusBar(this); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); WebSettings webSettings = wbInnerweb.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setSaveFormData(true); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); wbInnerweb.requestFocus(); wbInnerweb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); wbInnerweb.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.indexOf("tel:") < 0) { view.loadUrl(url); } return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { pbLoading.setVisibility(View.VISIBLE); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { pbLoading.setVisibility(View.GONE); wbInnerweb.setVisibility(View.VISIBLE); super.onPageFinished(view, url); } }); mUrl = getIntent().getStringExtra(PARAM_WEB_URL); wbInnerweb.loadUrl(mUrl); }
/* Initialize the Web view with some custom web settings that's helpful in previewing web data */ private void initWebView(final String content) { WebViewClient wvClient = new BaseWebviewClient(this); webView.setWebViewClient(wvClient); final WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); settings.setUseWideViewPort(true); final String mimeType = "text/html"; final String encoding = "UTF-8"; webView.loadDataWithBaseURL("", content, mimeType, encoding, ""); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_webview); String title = this.getIntent().getStringExtra("title"); String url = this.getIntent().getStringExtra("url"); backBtn = (Button) this.findViewById(R.id.backBtn); backBtn.setOnClickListener(this); shareBtn = (Button) this.findViewById(R.id.shareBtn); shareBtn.setOnClickListener(this); // 是否显示分享,默认不显示 boolean showShareBtn = this.getIntent().getBooleanExtra("SHOW_SHARE", false); shareBtn.setVisibility(showShareBtn ? View.VISIBLE : View.GONE); titleTextView = (TextView) this.findViewById(R.id.titleTextView); titleTextView.setText(title); webView = (NoZoomControllWebView) this.findViewById(R.id.webview); WebSettings setting = webView.getSettings(); setting.setJavaScriptEnabled(true); setting.setJavaScriptCanOpenWindowsAutomatically(true); setting.setSupportZoom(true); setting.setLoadsImagesAutomatically(true); setting.setBuiltInZoomControls(true); setting.setUseWideViewPort(true); setting.setLoadWithOverviewMode(true); setting.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); webView.loadUrl(url); webView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); }
private void loadWebViewUrl(String url) throws Exception { WebSettings settings = webviewAddScoin.getSettings(); settings.setJavaScriptEnabled(true); settings.setUseWideViewPort(true); webviewAddScoin.setHorizontalScrollBarEnabled(false); webviewAddScoin.setVerticalScrollBarEnabled(true); webviewAddScoin.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webviewAddScoin.setWebViewClient(new PaymentWebClient()); closeKeyBoard(); progressBar.setVisibility(VISIBLE); showWebView(true); webviewAddScoin.loadUrl(url); }
public synchronized void initPreferences() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); WebSettings webSettings = getSettings(); webSettings.setLoadWithOverviewMode(true); webSettings.setTextZoom(100); webSettings.setUseWideViewPort(true); webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true)); webSettings.setJavaScriptEnabled( sp.getBoolean(context.getString(R.string.sp_javascript), true)); webSettings.setJavaScriptCanOpenWindowsAutomatically( sp.getBoolean(context.getString(R.string.sp_javascript), true)); webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true)); webSettings.setSupportMultipleWindows( sp.getBoolean(context.getString(R.string.sp_multiple_windows), false)); webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true)); boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true); if (textReflow) { webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); } catch (Exception e) { } } } else { webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0")); if (userAgent == 1) { webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP); } else if (userAgent == 2) { webSettings.setUserAgentString( sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal)); } else { webSettings.setUserAgentString(userAgentOriginal); } int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0")); initRendering(mode); webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true)); }
@SuppressLint({"InflateParams", "SetJavaScriptEnabled"}) @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_home, null); webview = (WebView) view.findViewById(R.id.webView1_home); cookies = new ArrayList<Cookie>(); WebSettings ws = webview.getSettings(); ws.setJavaScriptEnabled(true); ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); ws.setSupportZoom(true); ws.setBuiltInZoomControls(true); ws.setUseWideViewPort(true); ws.setLoadWithOverviewMode(true); // ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webview.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webview.setOnKeyListener( new OnKeyListener() { @Override public boolean onKey(View arg0, int arg1, KeyEvent arg2) { if ((arg1 == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { webview.goBack(); return true; } return false; } }); setCookie(getActivity().getApplicationContext()); webview.loadUrl(devbaseURL + "?app-default"); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.instagram_demo_login); ButterKnife.bind(this); String cookieHost = Uri.parse(authInstragramLogin).getHost(); configureCookies(cookieHost); WebViewClient wvClient = new CIAWebViewClient(this); webView.setWebViewClient(wvClient); final WebSettings settings = webView.getSettings(); settings.setUserAgentString(BaseClient.USER_AGENT); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); settings.setUseWideViewPort(true); }
@SuppressLint("SetJavaScriptEnabled") private void initUI() { showLoading(); mContentWebView = (WebView) getView().findViewById(R.id.webview_content); WebSettings settings = mContentWebView.getSettings(); // 设置支持JavaScript settings.setJavaScriptEnabled(true); // 设置不缓存 settings.setCacheMode(WebSettings.LOAD_NO_CACHE); if (isSupportZoomByRatio()) { // 支持缩放 settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); // 按比例缩放 settings.setUseWideViewPort(true); // 自适应屏幕 settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); settings.setLoadWithOverviewMode(true); } // 在本地WebView中加载网页 mContentWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); hideLoading(); } }); String url = getUrl(); mContentWebView.loadUrl(url); }
void init() { setWebViewClient(new LoveClient()); setWebChromeClient(new Chrome()); WebSettings webSettings = getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setSaveFormData(false); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setLoadWithOverviewMode(false); webSettings.setUseWideViewPort(true); /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } }*/ }
private void loadWebViewContent() { // TODO Auto-generated method stub WebSettings webSettings = mWebView.getSettings(); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); // 启用支持javascript webSettings.setJavaScriptEnabled(true); mWebView.setBackgroundColor(Color.TRANSPARENT); // WebView加载web资源 mWebView.loadUrl("http://www.baidu.com/"); // 覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开 mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub // 返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器 view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (progressDialog != null) { progressDialog.dismiss(); progressDialog = null; } } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (progressDialog != null) { progressDialog.show(); } } }); }
private void setData(Mp4ba mp4ba) { if (null != name && !name.equals("")) { name = name.split("\\.")[0]; tv_head.setText(name); } String content = mp4ba.getContent(); webView.setVisibility(View.VISIBLE); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setDefaultFontSize(16); webView.requestFocusFromTouch(); // 支持获取手势焦点 webView.setWebViewClient( new WebViewClient() { // 打开网页时不调用系统浏览器, 而是在本WebView中显示 @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null); dialog.cancel(); }
public TiUIWebView(TiViewProxy proxy) { super(proxy); this.isFocusable = true; TiWebView webView = isHTCSenseDevice() ? new TiWebView(proxy.getActivity()) : new NonHTCWebView(proxy.getActivity()); webView.setVerticalScrollbarOverlay(true); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setJavaScriptEnabled(true); settings.setSupportMultipleWindows(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setAllowFileAccess(true); settings.setDomStorageEnabled( true); // Required by some sites such as Twitter. This is in our iOS WebView too. File path = TiApplication.getInstance().getFilesDir(); if (path != null) { settings.setDatabasePath(path.getAbsolutePath()); settings.setDatabaseEnabled(true); } File cacheDir = TiApplication.getInstance().getCacheDir(); if (cacheDir != null) { settings.setAppCacheEnabled(true); settings.setAppCachePath(cacheDir.getAbsolutePath()); } // enable zoom controls by default boolean enableZoom = true; if (proxy.hasProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) { enableZoom = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)); } settings.setBuiltInZoomControls(enableZoom); settings.setSupportZoom(enableZoom); if (TiC.JELLY_BEAN_OR_GREATER) { settings.setAllowUniversalAccessFromFileURLs( true); // default is "false" for JellyBean, TIMOB-13065 } // We can only support webview settings for plugin/flash in API 8 and higher. if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) { initializePluginAPI(webView); } boolean enableJavascriptInterface = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE), true); chromeClient = new TiWebChromeClient(this); webView.setWebChromeClient(chromeClient); client = new TiWebViewClient(this, webView); webView.setWebViewClient(client); if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) { client.getBinding().addJavascriptInterfaces(); } webView.client = client; if (proxy instanceof WebViewProxy) { WebViewProxy webProxy = (WebViewProxy) proxy; String username = webProxy.getBasicAuthenticationUserName(); String password = webProxy.getBasicAuthenticationPassword(); if (username != null && password != null) { setBasicAuthentication(username, password); } webProxy.clearBasicAuthentication(); } TiCompositeLayout.LayoutParams params = getLayoutParams(); params.autoFillsHeight = true; params.autoFillsWidth = true; setNativeView(webView); }
@SuppressLint({"SetJavaScriptEnabled"}) private void setupWebView(WebView paramWebView) { WebSettings localWebSettings = paramWebView.getSettings(); k.m.d(paramWebView, true); localWebSettings.setSupportZoom(true); localWebSettings.setBuiltInZoomControls(true); localWebSettings.setSupportZoom(true); localWebSettings.setUseWideViewPort(true); k.m.b(paramWebView, false); k.m.c(paramWebView, true); k.m.a(paramWebView, true); paramWebView.setScrollBarStyle(33554432); k.m.a(paramWebView); paramWebView.setWebViewClient( new WebViewClient() { private boolean b; private void a(String paramAnonymousString) { d.a(paramAnonymousString) .a( new c( A4S.get(DisplayView.this.getContext()), DisplayView.a(DisplayView.this), DisplayView.this)); } public void doUpdateVisitedHistory( WebView paramAnonymousWebView, String paramAnonymousString, boolean paramAnonymousBoolean) { DisplayView.e(DisplayView.this); } public void onPageFinished(WebView paramAnonymousWebView, String paramAnonymousString) { paramAnonymousString = paramAnonymousWebView.getBackground(); if (((paramAnonymousString instanceof ColorDrawable)) && (((ColorDrawable) paramAnonymousString).getAlpha() == 0)) { paramAnonymousWebView.setBackgroundColor(0); } if (DisplayView.f(DisplayView.this) != null) { DisplayView.f(DisplayView.this).setVisibility(8); } if (DisplayView.d(DisplayView.this) != null) { DisplayView.d(DisplayView.this).setChecked(false); } if (!this.b) { DisplayView.g(DisplayView.this); } while (DisplayView.a(DisplayView.this) == null) { return; } DisplayView.a(DisplayView.this).e(DisplayView.this); } public void onPageStarted( WebView paramAnonymousWebView, String paramAnonymousString, Bitmap paramAnonymousBitmap) { DisplayView.e(DisplayView.this); if (DisplayView.f(DisplayView.this) != null) { DisplayView.f(DisplayView.this).setVisibility(0); } if (DisplayView.d(DisplayView.this) != null) { DisplayView.d(DisplayView.this).setChecked(true); } } public void onReceivedError( WebView paramAnonymousWebView, int paramAnonymousInt, String paramAnonymousString1, String paramAnonymousString2) { this.b = true; } public boolean shouldOverrideUrlLoading( WebView paramAnonymousWebView, String paramAnonymousString) { a(paramAnonymousString); if (paramAnonymousString.startsWith("http")) { paramAnonymousWebView.loadUrl(paramAnonymousString); return true; } try { paramAnonymousWebView = Intent.parseUri(paramAnonymousString, 1); DisplayView.this.getContext().startActivity(paramAnonymousWebView); return true; } catch (Exception paramAnonymousWebView) { Log.error( "Error while browsing url : " + paramAnonymousString, paramAnonymousWebView); } return true; } }); }
public static void setupWebView(WebView webview) { webview.setVerticalScrollbarOverlay(true); WebSettings settings = webview.getSettings(); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); }
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { // get url and navigatio preference (default true) final String url = getIntent().getStringExtra(getPackageName() + ".URL"); final boolean navigation = getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true); setContentView(R.layout.webviewnav); // if we want navigation bar and not hide it, make it visible. Make it invisible if not. if (navigation && !hideNavigationBar) { findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE); } else { findViewById(R.id.webBottomBar).setVisibility(View.GONE); } mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack); mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward); mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop); mProgressView = (ProgressBar) findViewById(R.id.progressBar); mProgressView.setIndeterminate(true); // init webview mWebView = (WebView) findViewById(R.id.webView); // disable hw accel as it creates flickering pages, html5 video won't work with this if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16) mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); // This hides white bar on the right mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); WebSettings settings = mWebView.getSettings(); // enable plugins before java script settings.setPluginState(PluginState.ON); // TODO test these two settings with a big webpage (cafe lotty?) settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); // enable javascript and zoom controls settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); settings.setGeolocationEnabled(true); settings.setDatabaseEnabled(true); String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setGeolocationDatabasePath(databasePath); settings.setDomStorageEnabled(true); settings.setAppCacheEnabled(true); // allow XMLHttpRequests if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) settings.setAllowUniversalAccessFromFileURLs(true); MetaioWebViewClient client = new MetaioWebViewClient(); mWebView.setWebViewClient(client); mWebView.setWebChromeClient(new MetaioWebChromeClient()); registerForContextMenu(mWebView); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { // if we don't have to override the url, load it in the webview if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url); } } catch (Exception e) { MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e); } }
@Override protected void onStart() { super.onStart(); try { jsonSrc = FileUtils.readFromAssetsFile(that, "json2.js"); androidJsSrc = FileUtils.readFromAssetsFile(that, "android.js"); } catch (IOException e1) { throw new RuntimeException(e1); } mObserver = new HtmlEventObserver(); // TODO // RpcReceiverManager mFacadeManager = getRpcReceiverManager(); // mFacadeManager.getReceiver(EventFacade.class).addGlobalEventObserver(mObserver); // mAPIWrapperSource = generateAPIWrapper(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, config.getLOG_TAG()); mWebView.setKeepScreenOn(true); mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebView.setScrollbarFadingEnabled(false); mWebView.setVerticalScrollBarEnabled(false); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setScrollContainer(false); WebSettings webSettings = mWebView.getSettings(); webSettings.setSavePassword(false); webSettings.setSaveFormData(false); webSettings.setJavaScriptEnabled(true); webSettings.setPluginsEnabled(true); webSettings.setSupportZoom(false); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); mWebView.addJavascriptInterface(mWrapper, "_rpc_wrapper"); mWebView.addJavascriptInterface( new Object() { @SuppressWarnings("unused") public void register(String event, int id) { mObserver.register(event, id); } }, "_callback_wrapper"); if (Build.VERSION.SDK_INT >= 5) { try { Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[] {Boolean.TYPE}); m1.invoke(webSettings, Boolean.TRUE); Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[] {Boolean.TYPE}); m2.invoke(webSettings, Boolean.TRUE); Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[] {String.class}); m3.invoke(webSettings, this.getFilesDir().getParent() + "/databases/"); } catch (Exception e) { e.printStackTrace(); } } mWebView.setWebChromeClient(new WebChromeClient() {}); mWebView.setWebViewClient( new WebViewClient() { // public void onReceivedError(WebView view, int errorCode, String description, // String failingUrl) { // Toast.makeText(that, "Error: " + description, Toast.LENGTH_SHORT).show(); // } }); webSettings.setCacheMode(WebSettings.LOAD_NORMAL); if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 14) { mWebView.setSystemUiVisibility(WebView.STATUS_BAR_HIDDEN); } else if (Build.VERSION.SDK_INT >= 14) { mWebView.setSystemUiVisibility(WebView.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } mWebView.loadUrl("javascript:" + jsonSrc); mWebView.loadUrl("javascript:" + androidJsSrc); mWebView.loadUrl("javascript:" + mAPIWrapperSource); Log.d( config.getLOG_TAG(), "Launch Webview: " + "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME()); mWebView.loadUrl( "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME()); }