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; } }); }
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); } }
private WebView getWebView() { WebView wvSite = (WebView) findViewById(R.id.webview); wvSite.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); return wvSite; }
@Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.webview); ActionBar ab = getSupportActionBar(); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); ab.setDisplayShowTitleEnabled(true); ab.setDisplayHomeAsUpEnabled(true); mWebView = (WebView) findViewById(R.id.webView); mWebView.getSettings().setUserAgentString(Constants.USER_AGENT); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // load URL if one was provided in the intent String url = getIntent().getStringExtra("url"); if (url != null) { loadUrl(url); } }
/** 初始化工具栏网页视图 * */ private void initToolbarWebView() { toolbarWebView = (WebView) findViewById(R.id.webView2); toolbarWebView.getSettings().setJavaScriptEnabled(true); // 可用JS toolbarWebView.setScrollBarStyle(0); // 滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上 toolbarWebView.setWebViewClient( new WebViewClient() { public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if ("".equals(url) || url.equals("about:blank") || url.contains("about:blank")) { if (url.contains("about:blank")) { int idx = url.indexOf("?"); if (idx != -1) { appEventHandle(new AppEvent(url.substring(idx + 1))); Log.i("urlParams", url.substring(idx + 1)); } } return true; } view.loadUrl(toolbarPageUrl); return true; } }); toolbarWebView.setWebChromeClient( new WebChromeClient() { @Override public void onReceivedTitle(WebView view, String title) { super.onReceivedTitle(view, title); if (!title.isEmpty() && (title.toLowerCase().contains("error") || title.equalsIgnoreCase(getResources().getString(R.string.fileNotFound)))) { // Stop "app loading" spinner if showing view.loadUrl("file:///android_asset/www/error.html"); } } }); toolbarWebView.addJavascriptInterface( new Object() { @SuppressWarnings("unused") public void testCall() { runOnUiThread( new Runnable() { @Override public void run() { // 测试从js调java方法是否有问题 toolbarWebView.loadUrl("javascript:testCall()"); } }); } @SuppressWarnings("unused") public void eventHandle(String params) { appEventHandle(new AppEvent(params)); } }, "justepApp"); }
@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()); }
private void webViewInitialization(final Activity activity) { webView = (WebView) findViewById(R.id.webview); webView.setWebChromeClient( new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setProgress(progress * 1000); if (progress == 100 && progressDialog.isShowing()) progressDialog.dismiss(); } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = format( "Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}", consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId()); if (consoleMessage.messageLevel() == ERROR) { logError(message); reportException(message); } else { logDebug(message); } return true; } }); webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webView.addJavascriptInterface(formController, "formContext"); webView.addJavascriptInterface(navigationController, "navigationContext"); webView.addJavascriptInterface( new VillageController( context.allEligibleCouples(), context.listCache(), context.villagesCache()), "villageContext"); webView.addJavascriptInterface( new InternationalizationContext(getResources()), "internationalizationContext"); webView.addJavascriptInterface(context.anmLocationController(), ANM_LOCATION_CONTROLLER); webView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return true; } }); }
/** Sets up the WebView object and loads the URL of the page * */ private void setupWebView() { final WebView webview = getWebView(); webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); setWebViewClient(new MapWebViewClient(getActivity())); loadUrl(mUri.toString()); final WebSettings settings = webview.getSettings(); settings.setBuiltInZoomControls(false); /** Allows JavaScript calls to access application resources * */ webview.addJavascriptInterface(new JavaScriptInterface(), "android"); }
@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()); }
public void setWebView(WebView mWebView, Boolean event_add) { mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setSupportZoom(false); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { loadingFinished = false; view.loadUrl(urlNewString); return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { loadingFinished = false; pb.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { loadingFinished = true; pb.setVisibility(View.GONE); } }); if (event_add) { mWebView.addJavascriptInterface( new Object() { public void showInfo(String poster_id) { current_poster_id = poster_id; mHandler.post( new Runnable() { public void run() { Log.d("debug poster_id", current_poster_id); infoWebView.loadUrl( "file:///android_asset/www/info.html?poster_id=" + current_poster_id); unvisibleWebView(); infoWebView.setVisibility(View.VISIBLE); backButton.setVisibility(View.VISIBLE); } }); } }, "info"); } ; }
@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); }
@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.recipe_source_fragment, container, false); WebView browser = (WebView) view.findViewById(R.id.webView); browser.getSettings().setLoadsImagesAutomatically(true); browser.getSettings().setJavaScriptEnabled(true); browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); browser.loadUrl(sourceUrl); return view; }
private void setWebs() { getWebUrl(); new SettingWebParams().setWebs(webView); // 取消webView滑动时边框 webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webView.addJavascriptInterface(new JavaScriptCallSon(), "JavaScriptCall"); webView.setWebChromeClient(new MyWebChromeClient()); webView.setWebViewClient(new MyOwnWebViewClient()); // 设置cookie webView.loadUrl(webUrl); // //调试地址 // webView.loadUrl(GloableUtils.TestServerURL); }
@SuppressLint("NewApi") private void init() { initBackBtn(); WebView wv = (WebView) findViewById(R.id.wv); // wv.getSettings()// ¿ÉÓÃJS WebSettings ws = wv.getSettings(); // ws.setJavaScriptEnabled(true); ws.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 11) { ws.setDisplayZoomControls(true); } wv.setScrollBarStyle(0); wv.getSettings().setLoadWithOverviewMode(true); wv.getSettings().setUseWideViewPort(true); wv.loadUrl("file:///android_asset/about.html"); }
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); }
private void startWebView(String url) { webView.setWebViewClient( new WebViewClient() { ProgressDialog progressDialog; public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } public void onLoadResource(WebView view, String url) { if (progressDialog == null) { // in standard case YourActivity.this progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setMessage("Loading..."); progressDialog.show(); } } public void onPageFinished(WebView view, String url) { try { if (progressDialog.isShowing()) { view.clearCache(true); progressDialog.dismiss(); progressDialog = null; } } catch (Exception exception) { exception.printStackTrace(); } } }); /* String sayfa = "<html><body><h1>your own html</h1></body></html>"; webView.loadData(sayfa, "text/html", null); */ webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(true); webView.getSettings().setBuiltInZoomControls(true); webView.loadUrl(url); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View inflatedView = inflater.inflate(R.layout.fragment_sponsors_webview, container, false); webView = (WebView) inflatedView.findViewById(R.id.webview_sponsors); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.loadUrl(SPONSORS_URL); return inflatedView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.boring_activity_layout); TitleBar titleBar = (TitleBar) findViewById(R.id.boringLayoutTitleBar); titleBar.setTitle("Introduction to MIT"); LinearLayout mRoot = (LinearLayout) findViewById(R.id.boringLayoutRoot); WebView contentView = new WebView(this); contentView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); contentView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mRoot.addView(contentView); contentView.loadUrl("file:///android_asset/tour/intro_to_mit.html"); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mContext = this; // Lookup R.layout.main mLayout = (LinearLayout) findViewById(R.id.linearLayout); mWebView = new WebView(AndroidWebActivity.this); mWebView.setWebViewClient(new myWebViewClient()); mWebView.loadUrl(CommonUtils.PATH_ASSESTS_WWW + "index.html"); mWebView.setLayoutParams(mLayout.getLayoutParams()); mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); mWebView.getSettings().setJavaScriptEnabled(true); mLayout.addView(mWebView); }
private void loadWebView(WebView v) { // Set basic style v.setBackgroundColor(ContextCompat.getColor(this, R.color.color_background_dark)); v.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // Open links in external browser v.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } }); // Load HTML content from assets v.loadUrl(ASSETS_URI + Const.LocalAssets.LICENSE); }
protected void initWebViewSettings(WebView w) { w.setScrollbarFadingEnabled(true); w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); w.setMapTrackballToArrowKeys(false); // use trackball directly // Enable the built-in zoom w.getSettings().setBuiltInZoomControls(true); /// M: Add to disable overscroll mode w.setOverScrollMode(View.OVER_SCROLL_NEVER); final PackageManager pm = mContext.getPackageManager(); boolean supportsMultiTouch = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH) || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT); w.getSettings().setDisplayZoomControls(!supportsMultiTouch); // Add this WebView to the settings observer list and update the // settings final BrowserSettings s = BrowserSettings.getInstance(); s.startManagingSettings(w.getSettings()); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); UUID = getDeviceUUID(); // progressBar = ProgressDialog.show(SuperManActivity.this, // "SuperMan", "Loading..."); // progressBar = (ProgressBar) findViewById(R.id.progressBar); webView = (WebView) findViewById(R.id.webView); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.setWebChromeClient(new FileAttachmentChromeClient()); webView.setWebViewClient(new MyCustomWebViewClient()); webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); setCookie(URL, COOKIE_NAME, UUID); webView.loadUrl("http://www.hktcs.com/superman/landing.php"); new Handler().postDelayed(new GcmRunnable(), 100); // regist GCM }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarContentView(R.layout.info); setTitle(R.string.info_activity_title); webview = (WebView) findViewById(R.id.webview); webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webview.getSettings().setJavaScriptEnabled(false); webview.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url != null && url.startsWith("http://")) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else if (url != null && url.startsWith("mailto:")) { MailTo mailto = MailTo.parse(url); startActivity( Utils.createEMailComposeIntent( InfoActivity.this, mailto.getTo(), mailto.getSubject(), mailto.getBody(), mailto.getCc())); view.reload(); return true; } else { return false; } } }); webview.loadData(getRawResourceContent(R.raw.loading), "text/html", "UTF-8"); progressbar = (ProgressBar) findViewById(R.id.progressbar); new FetchInfoTask().execute(); }
private void webViewInitialization(final Activity activity) { webView = (WebView) findViewById(R.id.webview); webView.setWebChromeClient( new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { dismissProgressBarOnProgressComplete(progress, activity); } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = format( "Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}", consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId()); if (consoleMessage.messageLevel() == ERROR) { logError(message); reportException(message); } else { logDebug(message); } return true; } }); webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webView.addJavascriptInterface(formController, "formContext"); webView.addJavascriptInterface(navigationController, "navigationContext"); webView.addJavascriptInterface( new InternationalizationContext(getResources()), "internationalizationContext"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_view); ButterKnife.bind(this); setSupportActionBar(toolbar); assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Initialize the WebView webView.getSettings().setSupportZoom(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(true); webView.getSettings().setLoadsImagesAutomatically(true); webView.setWebViewClient(new WebViewClient()); Intent i = getIntent(); HqEntity hqEntity = (HqEntity) i.getSerializableExtra(Constants.HQ_KEY); allowCacheAccess(hqEntity.isCacheEnabled()); // Load the URLs inside the WebView, not in the external web browser webView.loadUrl(hqEntity.getUrl()); }
@Override protected void onCreate(Bundle savedInstanceState) { this.requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题栏 super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webview = (WebView) findViewById(R.id.webView_Main); webview.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); WebSettings setting = webview.getSettings(); setting.setJavaScriptEnabled(true); // 支持js setting.setDefaultTextEncodingName("GBK"); // 设置字符编码 webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // 滚动条风格,为0指滚动条不占用空间,直接覆盖在网页上 webview.loadUrl("http://42.200.39.108/"); }
@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; } }); }
private void renderView() { // reference final WebView webView = (WebView) mRootView.findViewById(R.id.fragment_main_webview); final AdView adView = (AdView) mRootView.findViewById(R.id.fragment_main_adview); // webview settings webView.getSettings().setBuiltInZoomControls(false); webView.getSettings().setSupportZoom(true); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.getSettings().setJavaScriptEnabled(true); webView.setBackgroundColor(getResources().getColor(R.color.global_bg_front)); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); // fixes scrollbar on Froyo webView.setWebChromeClient( new WebChromeClient() { public void openFileChooser(ValueCallback<Uri> filePathCallback) { mFilePathCallback4 = filePathCallback; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); startActivityForResult( Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER); } public void openFileChooser(ValueCallback filePathCallback, String acceptType) { mFilePathCallback4 = filePathCallback; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); startActivityForResult( Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER); } public void openFileChooser( ValueCallback<Uri> filePathCallback, String acceptType, String capture) { mFilePathCallback4 = filePathCallback; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); startActivityForResult( Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER); } @Override public boolean onShowFileChooser( WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { mFilePathCallback5 = filePathCallback; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); startActivityForResult( Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER); return true; } }); webView.setWebViewClient( new WebViewClient() { private boolean mSuccess = true; @Override public void onPageFinished(final WebView view, final String url) { runTaskCallback( new Runnable() { public void run() { if (getActivity() != null && mSuccess) { showContent( 500); // hide progress bar with delay to show webview content smoothly showActionBarProgress(false); } } }); } @Override public void onReceivedError( final WebView view, final int errorCode, final String description, final String failingUrl) { runTaskCallback( new Runnable() { public void run() { if (getActivity() != null) { mSuccess = false; showEmpty(); showActionBarProgress(false); } } }); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (DownloadUtility.isDownloadableFile(url)) { Toast.makeText(getActivity(), R.string.fragment_main_downloading, Toast.LENGTH_LONG) .show(); DownloadUtility.downloadFile(getActivity(), url, DownloadUtility.getFileName(url)); return true; } else if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) { // determine for opening the link externally or internally boolean external = isLinkExternal(url); boolean internal = isLinkInternal(url); if (!external && !internal) { external = WebViewAppConfig.OPEN_LINKS_IN_EXTERNAL_BROWSER; } // open the link if (external) { startWebActivity(url); return true; } else { showActionBarProgress(true); return false; } } else if (url != null && url.startsWith("mailto:")) { MailTo mailTo = MailTo.parse(url); startEmailActivity(mailTo.getTo(), mailTo.getSubject(), mailTo.getBody()); return true; } else if (url != null && url.startsWith("tel:")) { startCallActivity(url); return true; } else if (url != null && url.startsWith("sms:")) { startSmsActivity(url); return true; } else if (url != null && url.startsWith("geo:")) { startMapSearchActivity(url); return true; } else { return false; } } }); webView.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { WebView webView = (WebView) v; switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (webView.canGoBack()) { webView.goBack(); return true; } break; } } return false; } }); webView.requestFocus( View .FOCUS_DOWN); // http://android24hours.blogspot.cz/2011/12/android-soft-keyboard-not-showing-on.html webView.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; } }); // admob if (WebViewAppConfig.ADMOB && NetworkManager.isOnline(getActivity())) { AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(getString(R.string.admob_test_device_id)) .build(); adView.loadAd(adRequest); adView.setVisibility(View.VISIBLE); } else { adView.setVisibility(View.GONE); } }
private void initUI() { deleteDatabase("webview"); mWebView = (WebView) findViewById(R.id.webview); String channel = MyUtils.getChannel(this); mWebView.requestFocusFromTouch(); mWebView.setVerticalScrollBarEnabled(false); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setAllowFileAccess(true); mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); mWebView.getSettings().setUserAgentString("Android365/test"); mWebView.setWebChromeClient(webChromeClient); // mWebView.requestFocusFromTouch(); // mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); // mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); // mWebView.getSettings().setUserAgentString(NetworkControl.CLIENT_USER_AGENT + "/" + channel + // " " + getString(R.string.mversion)); // mWebView.setWebChromeClient(webChromeClient); // // WebSettings settings = mWebView.getSettings(); // settings.setJavaScriptEnabled(true); // if (android.os.Build.VERSION.SDK_INT < 8) { // settings.setPluginsEnabled(true); // } else { // settings.setPluginState(WebSettings.PluginState.ON); // } // settings.setSupportZoom(true); // settings.setBuiltInZoomControls(true); // settings.setAllowFileAccess(true); // settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); // settings.setUseWideViewPort(true); // if(android.os.Build.VERSION.SDK_INT >= 8){ // settings.setLoadWithOverviewMode(true); // settings.setDatabaseEnabled(true); // settings.setDomStorageEnabled(true); // settings.setGeolocationEnabled(true); // settings.setAppCacheEnabled(true); // } // // if (android.os.Build.VERSION.SDK_INT >= 11) { // Method method; // try { // method = WebSettings.class.getDeclaredMethod( "setDisplayZoomControls", // boolean.class); // method.setAccessible(true); // method.invoke(settings, false); // } // catch (Exception e) { // } // } follow = (CheckBox) findViewById(R.id.follow); progressBar = (ProgressBar) findViewById(R.id.progress_bar); bottom = (RelativeLayout) findViewById(R.id.bottom); if (show) { bottom.setVisibility(View.VISIBLE); hint = (TextView) findViewById(R.id.hint); hint.setText(Html.fromHtml("<u>" + getString(R.string.follow_hint) + "</u>")); hint.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(ThirdPartyAccoutActivity.this, BindHint.class); startActivity(intent); } }); follow.setText(followStr); follow.setChecked(true); } else { bottom.setVisibility(View.GONE); } }
@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()); }