如何让按钮上的文本使用html中的标签为android
问题描述:
我有webview在我的应用程序和webview有一个按钮。现在我想要在Android中使用锚定标签的按钮上使用html代码的文本。怎么可能。可谁能帮助我一个如何让按钮上的文本使用html中的标签为android
答
试试这个
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
final WebView webview = (WebView) findViewById(R.id.browser);
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webview.loadUrl("javascript:window.HtmlViewer.showHTML" +
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
}
});
webview.loadUrl("http://android-in-action.com/index.php?post/" +
"Common-errors-and-bugs-and-how-to-solve-avoid-them");
}
class MyJavaScriptInterface {
private Context ctx;
MyJavaScriptInterface(Context ctx) {
this.ctx = ctx;
}
public void showHTML(String html) {
new AlertDialog.Builder(ctx).setTitle("HTML").setMessage(html)
.setPositiveButton(android.R.string.ok, null).setCancelable(false).create().show();
}
}
}
https://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a-webview指这一点。 –