Adding 9-patch resource android

Started by
2 comments, last by alh420 9 years, 7 months ago
I'm trying to add a 9-patch image for a button.
Its supposed to be in the /res/drawable/ but I need an identifier in R.java. How do I do that?
I copied the .9.png image to all the res/drawable-*/. But I don't know how to get an $res. identifier.
Advertisement
So I'm not sure I follow.

You have a resource stored in your jar file. You also write you "need an identifier", which seems confusing. Normally you don't need an identifier, you need a stream for the resource.

The normal way of doing it is something like: InputStream is = getClass().getResourceAsStream("/res/caseSensitiveFileName.png");

That will allow you to stream whatever resource you need out of your file (recalling that jar files are nothing more than standard zip files which use a per-file stream-based encoding). Also remember that even if your system uses NTFS or FAT or another non-case-sensitive file system, the file table in zip is (and always has been) case sensitive.

It says I need to set the background using

android:background="@drawable/my_button_background"
But I don't know how to set a string in the string table to point to one of the /res/drawable/ resources.

Those identifiers should be automatically generated for you, so you should not need to add it anywhere, they should "just work".

Maybe your IDE needs to be refreshed or the project cleaned at rebuilt.

This topic is closed to new replies.

Advertisement