OKIEWARDOYO

ANDROID NO.7 1

Feb 10th, 2015
10,656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package mediatutorial.web.id.metuwebbrowser;
  2.  
  3. import android.support.v7.app.ActionBarActivity;
  4. import android.os.Bundle;
  5. import android.view.Menu;
  6. import android.view.MenuItem;
  7. import android.view.View;
  8. import android.webkit.WebSettings;
  9. import android.webkit.WebView;
  10. import android.webkit.WebViewClient;
  11. import android.widget.EditText;
  12.  
  13. public class MainActivity extends ActionBarActivity {
  14.     String theUrl = "";
  15.     public WebView webBrowserKu;
  16.  
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.         //loading setelah activity_main.xml terloading
  21.         webBrowserKu = (WebView)findViewById(R.id.myWebView);
  22.         //kita ingin supaya setiap link yang di click ditampilkan di WebView
  23.         webBrowserKu.setWebViewClient(new WebViewClient());
  24.         //enable kan Javascript
  25.         WebSettings theWebSetting = webBrowserKu.getSettings();
  26.         theWebSetting.setJavaScriptEnabled(true);
  27.     }
  28.  
  29.  
  30.     @Override
  31.     public boolean onCreateOptionsMenu(Menu menu) {
  32.         // Inflate the menu; this adds items to the action bar if it is present.
  33.         getMenuInflater().inflate(R.menu.menu_main, menu);
  34.         return true;
  35.     }
  36.  
  37.     @Override
  38.     public boolean onOptionsItemSelected(MenuItem item) {
  39.         // Handle action bar item clicks here. The action bar will
  40.         // automatically handle clicks on the Home/Up button, so long
  41.         // as you specify a parent activity in AndroidManifest.xml.
  42.         int id = item.getItemId();
  43.  
  44.         //noinspection SimplifiableIfStatement
  45.         if (id == R.id.action_settings) {
  46.             return true;
  47.         }
  48.  
  49.         return super.onOptionsItemSelected(item);
  50.     }
  51.  
  52.     public void gotoUrl(View view) {
  53.         EditText theEditText = (EditText)findViewById(R.id.urlTxt);
  54.         theUrl = theEditText.getText().toString();
  55.         //
  56.         webBrowserKu.loadUrl(theUrl);
  57.  
  58.     }
  59.  
  60.     public void goRefresh(MenuItem item) {
  61.         webBrowserKu.reload();
  62.     }
  63.  
  64.     public void goStop(MenuItem item) {
  65.         webBrowserKu.stopLoading();
  66.     }
  67.  
  68.     public void goBack(MenuItem item) {
  69.         webBrowserKu.goBack();
  70.     }
  71.  
  72.     public void goForward(MenuItem item) {
  73.         webBrowserKu.goForward();
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment