Как сделать, чтобы в html, загруженном в WebView, работали ссылки?

Html загружается из assets, там же находятся, другие html, css, script.
String webData = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webData = getHtmlFromAsset();

        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setSaveFormData(true);
        webView.addJavascriptInterface(new JavaScriptIntefeise(this), "Android");
        webView.loadDataWithBaseURL(getAssets().toString(), webData, "text/html", "UTF-8", null);
    }

    private String getHtmlFromAsset() {
        InputStream is;
        StringBuilder builder = new StringBuilder();
        String htmlString = null;
        try {
            is = getAssets().open(getString(R.string.context));
            if (is != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                String line;
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }

                htmlString = builder.toString();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return htmlString;
    }

    class JavaScriptIntefeise {

        Context ctx;

        public JavaScriptIntefeise(Context ctx) {
            this.ctx = ctx;
        }

    }

Структура html
<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<style>
a {
	text-decoration: none; /*подчеркивание ссылок*/
	color: #000000;			/*цвет ссылок*/
}
button {
	min-height: 8mm; /*мин высота пункта */
	width: 100%;		/*ширина пункта */
	text-align: left;	/*выравнивание*/
}
</style>

</head> 
<body> 

<form action="1.html"><button class="odd">I.</button></form>

<form action="2.html"><button class="even">II.</button></form>

<form action="3.html"><button class="odd">III. </button></form>

</body>
</html>

Причем вложенный стиль работает, а если вложить скрипт - он не работает.
  • Вопрос задан
  • 411 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы