@SuppressWarnings("deprecation") @SuppressLint("SetJavaScriptEnabled") public static void loadUrlAdaptiveScreen( Context mContext, WebView webview, String url, boolean javaScriptEnabled) { WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(javaScriptEnabled); // 自适应屏幕 // 第一种: // WebSetting settings = webView.getSettings(); // settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // 把所有内容放在webview等宽的一列中。(可能会出现页面中链接失效) // 第二种: // settings.setUseWideViewPort(true); // settings.setLoadWithOverviewMode(true); // 第三种: DisplayMetrics metrics = new DisplayMetrics(); ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; if (mDensity <= 120) { webSettings.setDefaultZoom(ZoomDensity.CLOSE); } else if (mDensity > 120 && mDensity < 240) { webSettings.setDefaultZoom(ZoomDensity.MEDIUM); } else if (mDensity >= 240) { webSettings.setDefaultZoom(ZoomDensity.FAR); } webview.setWebViewClient(new WebViewClient()); webview.loadUrl(url); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // 保持屏幕亮 // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); webview = (WebView) super.findViewById(R.id.webView); progress = (ProgressBar) super.findViewById(R.id.progress); // progress.setVisibility(View.GONE); webview.setWebChromeClient(new WebChromeClientImpl(handler)); webview.setWebViewClient(wc); // webview.setInitialScale(25); ws = webview.getSettings(); ws.setJavaScriptCanOpenWindowsAutomatically(true); ws.setJavaScriptEnabled(true); ws.setPluginState(PluginState.ON); ws.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); Log.i("---", "加载"); // ws.setSupportZoom(true); // ws.setBuiltInZoomControls(true);//设置支持缩放 // ws.setUseWideViewPort(true); webview.loadUrl("http://aaaadc.com"); // webview.loadUrl("http://www.oceanthree.hk/apps_shop/app_index.php"); }
@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; } }); }
/** Initialize the WebView options to the ones define by user. */ public void initializeOptions() { WebSettings settings = getSettings(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); settings.setJavaScriptEnabled( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true)); settings.setLoadsImagesAutomatically( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true)); settings.setSaveFormData( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true)); settings.setSavePassword( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true)); settings.setDefaultZoom( ZoomDensity.valueOf( prefs.getString( Constants.PREFERENCES_BROWSER_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString()))); settings.setUserAgentString( prefs.getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT)); settings.setPluginState( PluginState.valueOf( prefs.getString( Constants.PREFERENCES_BROWSER_ENABLE_PLUGINS, PluginState.ON_DEMAND.toString()))); CookieManager.getInstance() .setAcceptCookie(prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_COOKIES, true)); // Technical settings // settings.setUseWideViewPort(true); settings.setSupportMultipleWindows(true); setLongClickable(true); setScrollbarFadingEnabled(true); setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); setDrawingCacheEnabled(true); settings.setAppCacheEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); }
public View getView(int scaleInPercent) { if (null == view) view = View.inflate(context, R.layout.statistics_main_frame, null); if (null != selectItems) { selectButton = (Button) view.findViewById(R.id.statistics_category); selectButton.setVisibility(View.VISIBLE); if (selectItems.length > 0) { selectButton.setText(selectItems[0]); } if (selectItems.length < 2) { selectButton.setCompoundDrawables(null, null, null, null); } if (selectItems.length > 1 && null != selectUrl) { selectButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { GeneralInformationFragment general = new GeneralInformationFragment(); // String []status = {"未解决","已解决"}; general.setSingleChoiceItems( context, R.id.et_solvestatus, selectItems, 0, new GeneralInformationFragment.OnChangedListener() { @Override public void onChanged(int id, int which, String value) { // TODO Auto-generated method stub // ((EditText)view.findViewById(id)).setText(value); // Constants.obtainNetbaseinfoZhenyuUrl(value); if ("t_netbaseinfo".equalsIgnoreCase(kind)) { url = String.format( selectUrl, kind, Configuration.getInstance().getUsername(), value); selectButton.setText(value); } else { Configuration.getInstance().setEventTongJiTime(value); String time = Constants.eventTongjiMap.get(value); if (null == time) time = Constants.event_tongji_time[0]; url = String.format( selectUrl, kind, Configuration.getInstance().getUsername(), time); selectButton.setText(value + btnSuffixTxt); } loadUrl(url); // selectButton.setText(value); } }); } }); } } webView = (WebView) view.findViewById(R.id.main_webview); webView.setInitialScale(scaleInPercent); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); webSettings.setUseWideViewPort(false); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); // setZoomControlGone(webView); // webView.addJavascriptInterface(new Object() { // public void clickOnAndroid() { // mHandler.post(new Runnable() { // public void run() { // webView.loadUrl("javascript:wave()"); // } // }); // } // }, "demo"); // 如果页面中链接,如果希望点击链接继续在当前browser中响应, // 而不是新开Android的系统browser中响应该链接,必须覆盖webview的WebViewClient对象 webView.setWebViewClient( new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边 view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); ViewSingletonFactory.getInstance().hideProcessDialog(); } }); // btnCategory = (Button) view.findViewById(R.id.statistics_category); // btnCategory.setOnClickListener(onClickListener); if ("t_netbaseinfo".equalsIgnoreCase(kind)) { url = String.format(selectUrl, kind, Configuration.getInstance().getUsername(), selectItems[0]); } else { String value = Configuration.getInstance().getEventTongJiTime(); if (null == value) value = Constants.event_tongji_time_title[0]; String time = Constants.eventTongjiMap.get(value); selectButton.setText(value + btnSuffixTxt); if (null == time) time = Constants.event_tongji_time[0]; url = String.format(selectUrl, kind, Configuration.getInstance().getUsername(), time); } loadUrl(url); return view; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.resultpage); webView = (WebView) findViewById(R.id.webViewResults); Refresh = (Button) findViewById(R.id.ResultRefresh); Progress = (ProgressBar) findViewById(R.id.ResultsprogressBar); Refresh.setEnabled(false); Progress.setVisibility(View.VISIBLE); Refresh.setOnClickListener(this); WebSettings websettings = webView.getSettings(); websettings.setJavaScriptEnabled(true); websettings.setSavePassword(false); websettings.setSaveFormData(false); websettings.setSupportZoom(true); websettings.setDefaultZoom(ZoomDensity.MEDIUM); websettings.setAppCacheEnabled(false); webView.setWebViewClient( new WebViewClient() { public void onPageFinished(WebView view, String url) { if (Progress.getVisibility() == View.VISIBLE) { Progress.setVisibility(View.INVISIBLE); } } /*@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; }*/ }); /*webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if(progress == 100) activity.setTitle(R.string.app_name); } public void onPageFinished(WebView view, String url) { if (Progress.getVisibility() == View.VISIBLE) { Progress.setVisibility(View.INVISIBLE); } } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Handle the error } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); Progress.setVisibility( View.INVISIBLE); return true; } });*/ LoadWebView(); }