1. Configure the dialog XML file:
<resources>
<style name= "Dialogstylewindow" parent= "@android: Style/theme.dialog" >
<item name= "Android:windownotitle" >true</item>
<item name= "Android:windowframe" > @null </item>
<item name= "Android:windowisfloating" >true</item>
<item name= "Android:windowistranslucent" >true</item>
<item name= "Android:background" > @android:color/transparent</item>
<item name= "Android:windowbackground" > @android:color/transparent</item>
</style>
</resources>
2. Create layout XML Notice.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:orientation= "Vertical" >
<webview
Android:id= "@+id/webview1"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"/>
<imageview
Android:id= "@+id/close"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentright= "true"
Android:layout_alignparenttop= "true"
android:src= "@drawable/btn_close"/>
</RelativeLayout>
3, the Code implementation:
Import android.app.Activity;
Import Android.app.Dialog;
Import Android.app.ProgressDialog;
Import Android.view.Display;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.WindowManager;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;
Import Android.widget.ImageView;
public class Notice {
Activity mactivity;
Dialog noticedialog = null;
WebView WebView;
ProgressDialog Dialog;
Invoke this in the main activity
Public Notice (activity activity) {
Mactivity = activity;
}
U3d calls this function to show that WebView threading issues are recommended by handler way
public void Show () {
if (Noticedialog = = null) {
Noticedialog = new Dialog (Mactivity,r.style.dialogstylewindow);
}
View Contentview = Mactivity.getlayoutinflater (). Inflate (R.layout.notice,null);
ImageView closebtn = (ImageView) contentview
. Findviewbyid (R.id.close); Close Current WebView
Closebtn.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
TODO auto-generated Method Stub
Noticedialog.dismiss ();
WebView = null;
Noticedialog = null;
}
});
Dialog = Progressdialog.show (Mactivity,null, "Entering the Web, please later ...");
WebView = (WebView) Contentview.findviewbyid (R.ID.WEBVIEW1);
Webview.loadurl ("http://www.baidu.com");
Webview.getsettings (). Setjavascriptenabled (True);
Webview.setwebviewclient (New Webviewclient ());
Noticedialog.setcontentview (Contentview);
Noticedialog.setcanceledontouchoutside (FALSE);
Noticedialog.show ();
Set WebView fullscreen
WindowManager WindowManager = Mactivity.getwindowmanager ();
Display display = Windowmanager.getdefaultdisplay ();
Windowmanager.layoutparams LP = Noticedialog.getwindow (). GetAttributes ();
Lp.width = (int) (Display.getwidth ()); Set width
Lp.height = (int) (Display.getheight ());
Noticedialog.getwindow (). SetAttributes (LP);
}
Private class Webviewclient extends Android.webkit.WebViewClient {
@Override
public boolean shouldoverrideurlloading (WebView view, String URL) {
View.loadurl (URL);
return true;
}
@Override
public void onpagefinished (WebView view, String URL) {
TODO auto-generated Method Stub
Dialog.dismiss ();
}
}
}
[Original]unity3d call Android WebView