이 당신이 물건의 종류가 확실하지를 후 그러나 여기하는 것은 안드로이드 웹보기에서 클릭 활성화 SVG의 예입니다
WebView webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.w3.org/TR/SVG/images/script/script01.svg");
그것은 당신이 클릭 할 수있는 빨간색 원과 그 원의 변화의 크기를 표시해야합니다.
여기에 자산 폴더에서로드 SVG 당신이 당신의 SVG 파일에서 안드로이드 코드로 콜백을 할 수 있도록 노출 자바 스크립트 인터페이스 안드로이드와 재 작업 같은 예이다.
WebView webView;
public class WebAppInterface {
/** Show a toast from svg */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(MainActivity.this, toast, Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(), "Android");
String svg = loadSvg();
webView.loadData(svg, "image/svg+xml", "utf-8");
}
String loadSvg() {
try {
BufferedReader input = new BufferedReader(new InputStreamReader(
getAssets().open("test.svg")));
StringBuffer buf = new StringBuffer();
String s = null;
while ((s = input.readLine()) != null) {
buf.append(s);
buf.append('\n');
}
input.close();
return buf.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
과 test.svg 파일 :
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="6cm" height="5cm" viewBox="0 0 600 500"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Example script01 - invoke an ECMAScript function from an onclick event
</desc>
<!-- ECMAScript to change the radius with each click -->
<script type="application/ecmascript"> <![CDATA[
function circle_click(evt) {
Android.showToast("Hello from SVG");
var circle = evt.target;
var currentRadius = circle.getAttribute("r");
if (currentRadius == 100)
circle.setAttribute("r", currentRadius*2);
else
circle.setAttribute("r", currentRadius*0.5);
}
]]> </script>
<!-- Outline the drawing area with a blue line -->
<rect x="1" y="1" width="598" height="498" fill="none" stroke="blue"/>
<!-- Act on each click event -->
<circle onclick="circle_click(evt)" cx="300" cy="225" r="100"
fill="red"/>
<text x="300" y="480"
font-family="Verdana" font-size="35" text-anchor="middle">
Click on circle to change its size
</text>
</svg>
방법 터치를 처리 한 후 좌표를 사용하여 이미지를 강조 할 수있는 iamge보기의 맨 위에 오버레이를 만드는 방법에 대해? – blganesh101
기본적으로 webviews가있을 때 svgs 만 필요하다면 danbrough의 대답으로 집에 돌아와 말라 버릴까요? – Tom