अगर इस बात की तरह आप कर रहे हैं सुनिश्चित नहीं हैं के बाद, लेकिन यहाँ एक Android WebView में के क्लिक सक्षम 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 फ़ाइल से एंड्रॉइड कोड में कॉलबैक कर सकें।
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>
स्रोत
2013-07-16 13:36:22
आईमैज व्यू के शीर्ष पर ओवरले बनाने के बारे में, जो स्पर्श को संभाल सकता है और फिर निर्देशांक का उपयोग कर छवि को हाइलाइट कर सकता है? – blganesh101
यदि मूल रूप से आपको वेबव्यू के आसपास होने पर केवल svgs की आवश्यकता होती है, तो आप घर हैं और डैनब्रू के उत्तर के साथ सूखे हैं? – Tom