Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Adding 9-patch resource android


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 invutil   Crossbones+   -  Reputation: 1906

Like
0Likes
Like

Posted 25 August 2014 - 10:13 PM

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.


Sponsor:

#2 frob   Moderators   -  Reputation: 22692

Like
0Likes
Like

Posted 25 August 2014 - 10:47 PM

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.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 invutil   Crossbones+   -  Reputation: 1906

Like
0Likes
Like

Posted 25 August 2014 - 10:59 PM

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.


#4 Olof Hedman   Crossbones+   -  Reputation: 2947

Like
1Likes
Like

Posted 26 August 2014 - 01:02 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS