Android 动态修改SVG数据
这是一张svg的图 ,需求是动态修改上面的值.
1.首先用webview加载svg图
2.是需要知道 svg对应的标签 id
3.在onPageFinished后才能开始修改
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
startInterval();
}
});
4.动态修改
private void setElementValue(String id, String value) {
try{
double aDouble = Double.parseDouble(value);
value= decimalFormat.format(aDouble);
}catch (Exception e){
LogUtils.iTag("SVG",e.getMessage());
}
String js = "javascript:function updateValue() { \n" +
"document.getElementById(\"" + id + "\").textContent = \"" + value + "\";}";
wv.loadUrl(js);
wv.loadUrl("javascript:updateValue()");
}
ps:本信息需要用textContent来修改
链接: svgAPI.