2
A
回答
4
我想你想顯示其包含來自網頁視圖網頁視圖應用程序中的彈出窗口。
需要兩個步驟。首先,你需要重寫onJSAlert()方法在WebChromeClient類,以使在網頁視圖彈出窗口:
public class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
final JsResult finalJsResult = jsResult;
new AlertDialog.Builder(view.getContext()).setMessage(message).setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finalJsResult.confirm();
}
}).setCancelable(false).create().show();
return true;
}
}
,並添加到您的WebView:
MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
webView.setWebChromeClient(myWebChromeClient);
然後,您可以添加自定義網頁流量您AlertDialog(以取代AlertDialog以上):
public OnClickListener imageButtonViewOnClickListener = new OnClickListener() {
public void onClick(View v) {
LayoutInflater inflater = LayoutInflater.from(MyActivity.this);
View alertDialogView = inflater.inflate(R.layout.alert_dialog_layout, null);
WebView myWebView = (WebView) findViewById(R.id.DialogWebView);
myWebView.loadData(webContent, "text/html", "utf-8");
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
builder.setView(alertDialogView);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).show();
}
};
的XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<webView android:id="@+id/DialogWebView" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_marginLeft="20dip"
android:layout_marginRight="20dip" android:textAppearance="?android:attr/textAppearanceMedium" />
相關問題
- 1. Android - Webview在彈出對話框中?
- 2. 什麼是在WebView中顯示彈出對話框的最佳方式?
- 3. 彈出對話框
- 4. 什麼是Ruby on Rails的良好彈出對話框
- 5. android:彈出菜單,彈出對話框
- 6. jQuery對話框彈出
- 7. JQuery-mobile彈出/對話框?
- 8. WIX彈出對話框
- 9. Android彈出對話框
- 10. 創建對話框/彈出
- 11. 顯示彈出對話框
- 12. 彈出窗口對話框
- 13. 彈出對話框問題
- 14. 彈出樣式對話框
- 15. asp.net mvc&彈出對話框
- 16. 彈出對話框提交
- 17. 彈出jquery對話框
- 18. 彈出對話框 - iOS
- 19. Tkinter/Python彈出對話框
- 20. primefaces彈出對話框
- 21. android:在對話框或彈出窗口內的webview
- 22. 將進度條微調器添加到對話框彈出WebView
- 23. 如何處理WebView中的JavaScript對話框彈出
- 24. 彈出對話框無論用戶在做什麼
- 25. 爲什麼簡單的JQuery對話框/彈出不起作用?
- 26. asp.net中的彈出對話框發生了什麼mvc4
- 27. 爲什麼我的jQuery對話框不會彈出?
- 28. 爲什麼這個對話框不會彈出?(JSF2.0 + PRIMEFACES)
- 29. Android:爲什麼這個對話框會彈出兩次?
您是否知道我爲什麼會在 處出錯並顯示錯誤myWebView.loadData(webContent,「text/html」,「utf-8」); webContent無法解析? – Colby 2011-06-01 01:26:31
@Colby我想建議你先嚐試一個最簡單的webContent。像「myWebView.loadData(」
web content
「,」text/ html「,」utf-8「);」。希望這可以幫助。 – ThinkChris 2011-06-01 02:04:13@Colby Additionaly,你可能想知道loaddata()的限制,可以在這裏看到:http://groups.google.com/group/android-developers/browse_thread/thread/d7bf4187b731c6ae?pli=1 – ThinkChris 2011-06-01 02:07:07