Advertisement
Guest User

Untitled

a guest
Feb 1st, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. -----------------
  2. MainActivity.java
  3. -----------------
  4.  
  5. package app.webviewtest;
  6.  
  7. import android.support.v7.app.ActionBarActivity;
  8. import android.support.v7.app.ActionBar;
  9. import android.support.v4.app.Fragment;
  10. import android.os.Bundle;
  11. import android.view.LayoutInflater;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.os.Build;
  17. import android.webkit.WebSettings;
  18. import android.webkit.WebView;
  19.  
  20. public class MainActivity extends ActionBarActivity {
  21.  
  22. private WebView mWebView;
  23.  
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_main);
  28. // Enable Javascript
  29. WebSettings webSettings;
  30. webSettings = mWebView.getSettings();
  31. webSettings.setJavaScriptEnabled(true);
  32. mWebView = (WebView) findViewById(R.id.activity_main_webview);
  33. mWebView.loadUrl("http://google.com/");
  34. }
  35.  
  36.  
  37. @Override
  38. public boolean onCreateOptionsMenu(Menu menu) {
  39.  
  40. // Inflate the menu; this adds items to the action bar if it is present.
  41. getMenuInflater().inflate(R.menu.main, menu);
  42. return true;
  43. }
  44.  
  45. @Override
  46. public boolean onOptionsItemSelected(MenuItem item) {
  47. // Handle action bar item clicks here. The action bar will
  48. // automatically handle clicks on the Home/Up button, so long
  49. // as you specify a parent activity in AndroidManifest.xml.
  50. int id = item.getItemId();
  51. if (id == R.id.action_settings) {
  52. return true;
  53. }
  54. return super.onOptionsItemSelected(item);
  55. }
  56.  
  57. /**
  58. * A placeholder fragment containing a simple view.
  59. */
  60. public static class PlaceholderFragment extends Fragment {
  61.  
  62. public PlaceholderFragment() {
  63. }
  64.  
  65. @Override
  66. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  67. Bundle savedInstanceState) {
  68. View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  69. return rootView;
  70. }
  71. }
  72.  
  73. }
  74.  
  75.  
  76.  
  77. -----------------
  78. activity_main.xml
  79. -----------------
  80. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  81. xmlns:tools="http://schemas.android.com/tools"
  82. android:id="@+id/container"
  83. android:layout_width="match_parent"
  84. android:layout_height="match_parent"
  85. tools:context=".MainActivity"
  86. tools:ignore="MergeRootFrame">
  87. <WebView
  88. android:id="@+id/activity_main_webview"
  89. android:layout_width="match_parent"
  90. android:layout_height="match_parent" />
  91. </FrameLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement