標籤:android style http color java os io 檔案 ar
1、配置dialog xml檔案:
<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、建立布局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、代碼實現:
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;
//在主activity中調用 傳this進來
public Notice(Activity activity) {
mActivity = activity;
}
//u3d 調用這個函數顯示webview 線程問題 建議通過handler方式調用
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); //關閉當前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,"正在進入網頁,請稍後…");
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();
//設定webview全屏
WindowManager windowManager = mActivity.getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams lp = noticeDialog.getWindow().getAttributes();
lp.width = (int)(display.getWidth()); //設定寬度
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();
}
}
}
[原]unity3d調用android webView