[Original]unity3d call Android WebView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.