Created
October 22, 2015 15:29
-
-
Save LuizGadao/0c525dc803840fee8d6b to your computer and use it in GitHub Desktop.
simple webview with android.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.luizcarlos.bridhost; | |
import android.graphics.Bitmap; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.webkit.WebSettings; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
/** | |
* A placeholder fragmentMain containing a simple view. | |
*/ | |
public class MainActivityFragment extends Fragment { | |
WebView webView; | |
public MainActivityFragment() { | |
} | |
@Override | |
public View onCreateView( LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState ) { | |
return inflater.inflate( R.layout.fragment_main, container, false ); | |
} | |
@Override | |
public void onViewCreated( View view, Bundle savedInstanceState ) { | |
super.onViewCreated( view, savedInstanceState ); | |
String url = "http://bridhost.com.br/cliente/clientarea.php"; | |
webView = ( WebView ) view.findViewById( R.id.webview ); | |
WebSettings settings = webView.getSettings(); | |
settings.setJavaScriptEnabled( true ); | |
settings.setLoadWithOverviewMode( true ); | |
settings.setUseWideViewPort( true ); | |
//settings.setBuiltInZoomControls( true ); | |
webView.setWebViewClient( new myWebClient() ); | |
webView.loadUrl( url ); | |
} | |
public boolean canGoBack(){ | |
return webView != null && webView.canGoBack(); | |
} | |
public void goBack(){ | |
if (webView != null) | |
webView.goBack(); | |
} | |
public static class myWebClient extends WebViewClient { | |
@Override | |
public void onPageStarted(WebView view, String url, Bitmap favicon) { | |
// TODO Auto-generated method stub | |
super.onPageStarted(view, url, favicon); | |
} | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
// TODO Auto-generated method stub | |
view.loadUrl(url); | |
return true; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment