forked from hussien89aa/AndroidTutorialForBeginners
-
Notifications
You must be signed in to change notification settings - Fork 2
/
WebView.txt
122 lines (97 loc) · 3.52 KB
/
WebView.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hussienalrubaye.androidpermission.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:hint="Enter URL"
android:ems="10"
android:id="@+id/etURL"
android:layout_weight="1" />
<Button
android:onClick="buGo"
android:text="Go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:onClick="buBack"
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:layout_weight="1" />
<Button
android:text="Forword"
android:onClick="buForword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_weight="1" />
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wv1" />
</LinearLayout>
</RelativeLayout>
// java code
public class MainActivity extends AppCompatActivity {
//TextView tvDisplay;
EditText etURL;
WebView wv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// tvDisplay=(TextView)findViewById(R.id.tvDisplay);
wv1=(WebView)findViewById(R.id.wv1);
wv1.setWebViewClient(new myWebView());
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
etURL=(EditText)findViewById(R.id.etURL);
wv1.loadUrl("http://alruabye.net");
}
public void buGo(View view) {
LoadURL(etURL.getText().toString());
}
void LoadURL(String url){
this.url=url;
wv1.loadUrl(url);
}
public void buBack(View view) {
wv1.goBack();
}
public void buForword(View view) {
wv1.goForward();
}
private class myWebView extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
return true;
}
}
}
//acces to internet
<uses-permission android:name="android.permission.INTERNET"></uses-permission>