Sign in to follow this  
polyfrag

Adding 9-patch resource android

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this