How to show the SVG image in the android imageview - java

I have downloaded the svg-android library from the google code and parsed the SVG image using the SVG parser of svg-android as shown but its displaying nothing.
SVG CODE
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="500px" height="500px" viewBox="0 0 500 500" enable-background="new 0 0 500 500" xml:space="preserve">
<g id="max_width__x2F__height" display="none">
<path display="inline" d="M499.001,1v498H1V1H499.001 M500.001,0H0v500h500.001V0L500.001,0z"/>
</g>
<g id="androd">
<path fill="#9FBF3B" d="M301.314,83.298l20.159-29.272c1.197-1.74,0.899-4.024-0.666-5.104c-1.563-1.074-3.805-0.543-4.993,1.199
L294.863,80.53c-13.807-5.439-29.139-8.47-45.299-8.47c-16.16,0-31.496,3.028-45.302,8.47l-20.948-30.41
c-1.201-1.74-3.439-2.273-5.003-1.199c-1.564,1.077-1.861,3.362-0.664,5.104l20.166,29.272
c-32.063,14.916-54.548,43.26-57.413,76.34h218.316C355.861,126.557,333.375,98.214,301.314,83.298"/>
<path fill="#FFFFFF" d="M203.956,129.438c-6.673,0-12.08-5.407-12.08-12.079c0-6.671,5.404-12.08,12.08-12.08
c6.668,0,12.073,5.407,12.073,12.08C216.03,124.03,210.624,129.438,203.956,129.438"/>
<path fill="#FFFFFF" d="M295.161,129.438c-6.668,0-12.074-5.407-12.074-12.079c0-6.673,5.406-12.08,12.074-12.08
c6.675,0,12.079,5.409,12.079,12.08C307.24,124.03,301.834,129.438,295.161,129.438"/>
<path fill="#9FBF3B" d="M126.383,297.598c0,13.45-10.904,24.354-24.355,24.354l0,0c-13.45,0-24.354-10.904-24.354-24.354V199.09
c0-13.45,10.904-24.354,24.354-24.354l0,0c13.451,0,24.355,10.904,24.355,24.354V297.598z"/>
<path fill="#9FBF3B" d="M140.396,175.489v177.915c0,10.566,8.566,19.133,19.135,19.133h22.633v54.744
c0,13.451,10.903,24.354,24.354,24.354c13.451,0,24.355-10.903,24.355-24.354v-54.744h37.371v54.744
c0,13.451,10.902,24.354,24.354,24.354s24.354-10.903,24.354-24.354v-54.744h22.633c10.569,0,19.137-8.562,19.137-19.133V175.489
H140.396z"/>
<path fill="#9FBF3B" d="M372.734,297.598c0,13.45,10.903,24.354,24.354,24.354l0,0c13.45,0,24.354-10.904,24.354-24.354V199.09
c0-13.45-10.904-24.354-24.354-24.354l0,0c-13.451,0-24.354,10.904-24.354,24.354V297.598z"/>
</g>
</svg>

If you use this svg-android lib (and I think so), then you can see that there are some tutorials.
In short, you should do in this case something like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a new ImageView
ImageView imageView = new ImageView(this);
// Set the background color to white
imageView.setBackgroundColor(Color.WHITE);
// Parse the SVG file from the resource
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
// Get a drawable from the parsed SVG and set it as the drawable for the ImageView
imageView.setImageDrawable(svg.createPictureDrawable());
// Set the ImageView as the content view for the Activity
setContentView(imageView);
}
If you saw this, and do the same, then there may be problems with your SVG. Did you try to open it somewhere else? Or better paste here source of your SVG, please

Related

Glide error with ?attr/color use in drawable

I have ic_test.xml in drawable folder.
ic_test.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/black"
android:pathData="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />
</vector>
when I use Glide for load, Glide not work because I use "?attr/black" for "fillColor", if I use "#color/black", Glide is work. anyWay can fix this?
Glide.with(getContext())
.load(R.drawable.ic_test)
.apply(new RequestOptions().transforms(new CenterCrop()))
.into(this);
Add this to your styles.xml:
<item name="black">#000000</item>
? is only for accessing styles.xml not colors.xml.
use #android:color/black
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#android:color/black"
android:pathData="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />

How to Set fillColor, StrokeWidth and StrokeColor of vector drawable programatically in Android

I have searched a lot about changing fillColor , strokeColor and strokeWidth of a vector drawable but didn't found anything.
This is the vector drawable:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="300"
android:viewportHeight="300"
android:width="300dp"
android:height="300dp">
<path
android:pathData="M150.412,10.422999999999973,C227.47,10.422999999999973,289.93100000000004,72.81,289.93100000000004,149.771,C289.93100000000004,226.73,227.47,289.119,150.412,289.119,C73.36,289.119,10.893,226.73,10.893,149.771,C10.893,72.81,73.36,10.422999999999973,150.412,10.422999999999973z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#010101"
android:strokeMiterLimit="10" />
If I want to Change its FillColor, StrokeColor and StrokeWidth using Xml then code for that will be the following one:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="300"
android:viewportHeight="300"
android:width="300dp"
android:height="300dp">
<path
android:pathData="M150.412,10.422999999999973,C227.47,10.422999999999973,289.93100000000004,72.81,289.93100000000004,149.771,C289.93100000000004,226.73,227.47,289.119,150.412,289.119,C73.36,289.119,10.893,226.73,10.893,149.771,C10.893,72.81,73.36,10.422999999999973,150.412,10.422999999999973z"
android:strokeLineJoin="round"
android:strokeWidth="10"
android:fillColor="#f50d0d"
android:strokeColor="#f1e904"
android:strokeMiterLimit="10" />
How can I achieve this programmatically via Java code?

How to customize a vector in Android Studio?

I am working with an Android app (using API 21) in which I can change the color of a vector manually depends on previous Activity, but I have a problem, I can not access the 'Path' object in my xml file
<!-- drawable/chevron_left.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:name="left"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:id="#+id/chervon_left"
android:fillColor="#000"
android:pathData="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z" />
</vector>
So how can I customize this vector in MainActivity.java file ?
I read this but it did not work: Working with Drawables
basically, use #color.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:name="left"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:id="#+id/chervon_left"
android:fillColor="#color/purple_200"
android:pathData="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z" />

SVG image changing color

I'm new to SVG and i need to make an SVG that change his color in 1 second from white to red and than stay red for another 2 seconds.
I know how to change the color in 1 second but i can't find any method to set the color red before restarting.
this is my image.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- The icon can be used freely in both personal and commercial projects with no attribution required, but always appreciated.
You may NOT sub-license, resell, rent, redistribute or otherwise transfer the icon without express written permission from iconmonstr.com -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
x="0px"
y="0px"
width="512px"
height="512px"
viewBox="0 0 512 512"
enable-background="new 0 0 512 512"
xml:space="preserve"
id="svg2"
inkscape:version="0.48.4 r9939"
sodipodi:docname="alarm_animate.svg"><metadata
id="metadata10"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
id="defs8" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1024"
id="namedview6"
showgrid="false"
inkscape:zoom="1.84375"
inkscape:cx="178.41033"
inkscape:cy="264.79565"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<animateColor
id="a1"
attributeName="fill"
from="#FFFFFF"
to="#FF0000"
dur="1s"
repeatCount="indefinite" />
<path
id="warning-6-icon"
d="m 237.939,231.352 36.121,0 0,97.421 -36.121,0 z M 256,381.019 c -9.574,0 -19.334,-9.761 -19.334,-19.334 0,-9.574 9.76,-19.335 19.334,-19.335 9.573,0 19.334,9.761 19.334,19.335 0,9.573 -9.761,19.334 -19.334,19.334 z M 256,74.07 46,438.873 l 420,0 z m 0,88 132.718,230.803 -265.436,0 z"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccssssscccccccc" />
</svg>
any suggestions?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- The icon can be used freely in both personal and commercial projects with no attribution required, but always appreciated.
You may NOT sub-license, resell, rent, redistribute or otherwise transfer the icon without express written permission from iconmonstr.com -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
x="0px"
y="0px"
width="512px"
height="512px"
viewBox="0 0 512 512"
enable-background="new 0 0 512 512"
xml:space="preserve"
id="svg2"
inkscape:version="0.48.4 r9939"
sodipodi:docname="alarm_animate.svg"><metadata
id="metadata10"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
id="defs8" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1024"
id="namedview6"
showgrid="false"
inkscape:zoom="1.84375"
inkscape:cx="178.41033"
inkscape:cy="264.79565"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<animate
id="a1"
attributeName="fill"
from="#FFFFFF"
to="#FF0000"
dur="1s"
begin="0s; a2.end" />
<animate
id="a2"
attributeName="fill"
from="#FF0000"
to="#FF0000"
dur="2s"
begin="a1.end"
fill="freeze" />
<path
id="warning-6-icon"
d="m 237.939,231.352 36.121,0 0,97.421 -36.121,0 z M 256,381.019 c -9.574,0 -19.334,-9.761 -19.334,-19.334 0,-9.574 9.76,-19.335 19.334,-19.335
9.573,0 19.334,9.761 19.334,19.335 0,9.573 -9.761,19.334 -19.334,19.334 z M 256,74.07 46,438.873 l 420,0 z m 0,88 132.718,230.803 -265.436,0 z"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccssssscccccccc" />
</svg>

How to locate custom html elements using selenium webdriver

I have the following html code
<svg height="600" width="910" xmlns:xlink="http://www.w3.org/1999/xlink"
id="svgcontent" overflow="visible" x="910" y="600" viewBox="0 0 910 600">
<g style="pointer-events:all">
<text fill="rgb(0,0,0)" font-family="Sans-Serif" font-size="13" id="80-155-126"
transform="rotate(-90, 168, 126)" y="126" x="168" style="pointer-
events:inherit">A100A</text>
</g>
</svg>
I tried in the following way but didnt get succeeded
assertEquals(driver.findElements(By.xpath("//*[local-name()='svg'
and namespace-uri()='http://www.w3.org/2000/svg' and #id='svgcontent']//*[local-
name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/text")).size(), 1);
try following
assertEquals(driver.findElements(By.xpath("//*[local-name()='svg' and #id='svgcontent']//*[local-name()='text']")).size(), 1);
it should work, but
assertEquals(driver.findElements(By.xpath("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg' and #id='svgcontent']//*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='text']")).size(), 1);
should be also ok.

Categories