У меня есть HTML-форма внутри WebView. Элемент управления формы выглядит как обычная кнопка, но на самом деле это HTML-файл с прозрачным фоном. Когда я нажимаю кнопку отправки HTML, я хочу, чтобы результат открывался в браузере, а не в веб-просмотре. В настоящее время он открывается в текущем WebView, который разрушает мой макет.
Как мне это сделать?
Вот моя форма
<string name="googlecheckout_html_button">
<![CDATA[
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
<head>
<title>Google Checkout Button</title>
<script type=\"text/javascript\" language=\"javascript\">
function pass() {
return javaInterface.checkboxPass();
}
</script>
</head>
<body>
<form style=\"width: 121px;margin-left: auto;margin-right: auto;\" onsubmit=\"return pass();\" action=\"https://%1$sapi/checkout/v2/checkoutForm/Merchant/%2$s\" id=\"BB_BuyButtonForm\" method=\"post\" name=\"BB_BuyButtonForm\">
<input name=\"item_name_1\" type=\"hidden\" value=\"%3$s\" />
<input name=\"item_description_1\" type=\"hidden\" value=\"%3$s\" />
<input name=\"item_quantity_1\" type=\"hidden\" value=\"1\" />
<input name=\"item_price_1\" type=\"hidden\" value=\"%4$s\" />
<input name=\"item_currency_1\" type=\"hidden\" value=\"%5$s\" />
<input name=\"_charset_\" type=\"hidden\" value=\"utf-8\" />
<input type=\"hidden\" name=\"shopping-cart.items.item-1.merchant-private-item-data\" value=\"%6$s\" />
<input alt=\"Pay With Google Checkout\" src=\"https://%1$sbuttons/buy.gif?merchant_id=%2$s&w=121&h=44&style=trans&variant=text&loc=en_US\" type=\"image\" />
</form>
</body>
</html>
]]>
</string>
Затем я использую String.format (arg ...) для заполнения полей соответствующими значениями.
Вот по WebView
String form = String.format(getString(R.string.googlecheckout_html_button),
host,
merchantId,
item_name_1,
item_price_1,
item_currency_1,
private_item_data
);
if(Logging.DEBUG) Log.d(TAG, form);
browser = new WebView(ActivityActivate.this);
browser.setBackgroundColor(0);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
browser.getSettings().setSupportZoom(true);
browser.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
return false;
}
});
//browser.getSettings().setLoadsImagesAutomatically(true);
browser.addJavascriptInterface(new JavascriptInterface(), "javaInterface");
//browser.loadData(header+formData+footer, "text/html", "UTF-8");
browser.loadDataWithBaseURL("https://checkout.google.com", form, "text/html", "UTF-8", null);
llPaymentButtons.addView(browser);