Search code examples
androidkotlinresourcesandroid-vectordrawable

android resource string transformed. why?


pathData.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="goseong">M340.083,66.939l13.334,-7l-8.334,-17.5l-1.333,-4.333l-7.167,-10l1.334,-1.833l-8,-14.167V8.939l-6.5,-8.333l-5.334,2.167L317.75,16.94l-1.167,7.833l-10.166,12.833l2.833,2l2.5,0.833l0.833,0.167l-1,1.833l0.667,4.333l5.5,-1.5l1,3.667l0.833,5.5l4.167,0.333l1,3.833l3.667,1l3.833,-1.833l2.167,2.5v5.5L340.083,66.939z</string>
</resources>

and fragment code

pathData = R.string.goseong.toString()
Log.d("pathData",pathData)
val pathValue: Path = PathParser.createPathFromPathData(pathData)

In Log cat,

expected:

D/pathData: M340.083,66.939l13.334,-7l-8.334,-17.5l-1.333,-4.333l-7.167,-10l1.334,-1.833l-8,-14.167V8.939l-6.5,-8.333l-5.334,2.167L317.75,16.94l-1.167,7.833l-10.166,12.833l2.833,2l2.5,0.833l0.833,0.167l-1,1.833l0.667,4.333l5.5,-1.5l1,3.667l0.833,5.5l4.167,0.333l1,3.833l3.667,1l3.833,-1.833l2.167,2.5v5.5L340.083,66.939z

but I got:

D/pathData: 2131820687

why string data transformed? I don't know why..


Solution

  • Its not transformed you are getting a resource reference. R.string.goseong.toString()This will always return an int like you have.

    You need to do context.getString(R.string.goseong)

    Also it looks like your storing some svg path data in a string. I'm not sure as to your use case but you might benefit from using vector drawables if your trying to turn that path into an image.