I can't write my blog for the first time. I'm not very competent. I hope you will give me more advice!
(I don't know how it works)
App
Package GG. Demo. Web;
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. WebKit. webview;
Import Android. WebKit. webviewclient;
/** I don't know if this is true ???
*
* You can consider the direction of this idea. Let's take a look at the rest.
*
*
* @ Author app
*
*/
Public class mainactivity extends activity implements onclicklistener {
Myweb my;
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main );
My = (myweb) This. findviewbyid (R. Id. webview );
This. findviewbyid (R. Id. One). setonclicklistener (this );
This. findviewbyid (R. Id. Two). setonclicklistener (this );
This. findviewbyid (R. Id. Three). setonclicklistener (this );
My. setwebviewclient (New webviewclient (){
Public Boolean shouldoverrideurlloading (webview view, string URL ){
Super. shouldoverrideurlloading (view, URL );
View. loadurl (URL );
Return true;
}
});
}
String tag = "system. Out ";
String str1 = "http://www.baidu.com ";
String str2 = "http://www.163.com ";
String str3 = "http://www.csdn.net ";
Public void onclick (view v ){
Switch (V. GETID ()){
Case R. Id. One:
My. Load (mainactivity. This, str1 );
Break;
Case R. Id. Two:
My. Load (mainactivity. This, str2 );
Break;
Case R. Id. Three:
My. Load (mainactivity. This, str2 );
Break;
}
}
}
Rewrite webview.
Package GG. Demo. Web;
Import java. util. arraylist;
Import Android. annotation. suppresslint;
Import Android. content. context;
Import Android. util. attributeset;
Import Android. View. view;
Import Android. WebKit. webview;
@ Suppresslint ("newapi ")
Public class myweb extends webview {
Private arraylist <webview> webs = new arraylist <webview> ();
Private myweb web = this;
Public myweb (context ){
Super (context );
}
Public myweb (context, attributeset attrs ){
Super (context, attrs );
}
Public myweb (context, attributeset attrs, int defstyle ){
Super (context, attrs, defstyle );
}
Public myweb (context, attributeset attrs, int defstyle,
Boolean privatebrowsing ){
Super (context, attrs, defstyle, privatebrowsing );
}
Private int flag = 0;
Public void load (context, string URL ){
Webview W = this;
Webs. Add (w );
W. settag (FLAG );
Flag ++;
W. loadurl (URL );
}
Public void stop (view v ){
Int I = integer. parseint (V. gettag (). tostring ());
Webview = webs. Get (I );
Webview. stoploading ();
}
Public void stopothers (view v ){
Int J = integer. parseint (V. gettag (). tostring ());
For (int K = 0; k <webs. Size (); k ++ ){
If (J! = K ){
Webview we = webs. Get (k );
We. stoploading ();
}
}
}
}
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Xmlns: Tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<Linearlayout
Android: Id = "@ + ID/top"
Android: layout_width = "fill_parent"
Android: layout_height = "45dip"
Android: Orientation = "horizontal">
<Button
Android: Id = "@ + ID/One"
Android: layout_width = "wrap_content"
Android: layout_height = "45dip"
Android: text = "button-1"/>
<Button
Android: Id = "@ + ID/Two"
Android: layout_width = "wrap_content"
Android: layout_height = "45dip"
Android: text = "button-22"/>
<Button
Android: Id = "@ + ID/three"
Android: layout_width = "wrap_content"
Android: layout_height = "45dip"
Android: text = "button-333"/>
</Linearlayout>
<GG. Demo. Web. myweb
Android: Id = "@ + ID/webview"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_below = "@ + ID/top"/>
</Relativelayout>