I know this is a simple question, so hopefully it won't be a bother to anyone.
How can I have a constant float value in my project that I can access from a View
's XML and .java file?
I've tried setting a float value in my View
's resource file as such:
<attr name="cornerRadius" format="float">15.0dp</attr>
I believe thats how it should be done, but I just did it using intuition. I'm really struggling on what to google on this subject.
Now, for accessing it in Java, I've tried this:
float myFloat = getContext().obtainStyledAttributes(attrs, R.styleable.MyView).getFloat(R.styleable.MyView_cornerRadius, 0.0f);
This is throwing me off, since its not getting the right value, but rather the value that I pass in the function. Why am I passing a float value to this function? There must be a different option.
Now, where the biggest problem is for me is accessing it in the XML.. I've tried this:
<corners android:radius="@attrs_my_view/cornerRadius"/>
I also tried this:
<corners android:radius="@float/cornerRadius"/>
But to no avail.
Maybe all of this is completely wrong, but I don't know how to search for this in google, because I don't know what its called. Its like having to look up a word in a dictionary based on its meaning. Its not a good time.