Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

Adding 9-patch resource android

Started by polyfrag 2 replies 1.8k views
Original Post
polyfrag
polyfrag
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.
frob
frob
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.
polyfrag
polyfrag

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.
alh420
alh420

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.