Creating a theme
So, now that we’ve got the framework-res.apk onto our hard drive, we can take a look at creating a theme. The only skill that is really required to change the appearance of the framework (this is the system file that contains the notification bar, settings etc.) is being able to edit .png image files to suit your tastes. If you can do this then it is just a matter of knowing how to extract the images, and how to update the .apk with them after editing.
Before we start we need to take a look at a special kind of image in android apk’s: the .9.png’s. These are recognisable, as the name suggests, by the double extension *.9.png.
.9.png's are images with a bit of extra information embedded. They contain information on how they can be stretched, and where the content can go (e.g. for a button background, which area of the background can contain the text).
This information is contained in a single pixel border (the guides
) around the image and can be added using draw9patch
. The catch here is that the guides must be compiled into the image before it can be used.
For the most part, you will not have to edit the border of a .9.png because, as long as you follow the guide below, the guides will already be in the image and you will not need to change them. If you do need to create your own (I’d assume you know enough not to be reading this though
), you can find more information here
Editing the Framework
In this example we will look at editing framework-res.apk
. However, the process can be used on any apk.
The method described below may seem overly complicated for those who have experience in this area, but it is (in my opinion) the easiest ‘sure-fire’ way to make sure you don’t have any problems (especially with the .9.png’s).
In rare cases, when the .apk your modifying doesn’t have any .9.png’s (e.g. the Recent Calls widget) then you can skip straight to the ‘Updating images using Drag/Drop’ section below.
You will need the following:
- this is included in the attached file themes.zip
Some people use WinRAR instead of 7zip, but apktool uses some 7zip commands internally so make sure it is installed (I think, I know this is the case for APK Manager, I still need to test this for apktool, but hey, just use 7zip, it's free and works exceptionally well).
In the attached zip file (themes.zip
) you will find a copy of my theme creation environment. It’s not too complicated, it only contains a couple of folders so I know where everything is, three key batch files (all one-liners) and apktool
The first thing we need to look at is install_framework.bat. This contains the following line:
java -jar apktool.jar install-framework stock\framework-res.apk
All this does is tell apktool to install the framework on your system. The resources from stock\framework-res.apk will be extracted to a default location. If you don’t do this then you will not be able to recompile other apk’s that rely on the framework (you will get a ResourceNotFound error).
The other batch files decompile and build the framework, these are the ones that need to be modified if you start working on a different apk:
java -jar apktool.jar d stock\ framework-res.apk working\ framework-res
java -jar apktool.jar b working\framework-res out\framework-res.apk
I have included the stock X10 framework. If you use on of the other frameworks out there you may find that you get a lot of errors when trying to recompile. That’s because someone got lazy with the .9.png’s
As we are modifying the framework directly we do not need to run install_framework.bat, for a different apk (e.g. Phonebook.apk) you may need to run this first to avoid errors when decompiling.
Decompiling and Building:
1. Run decompile.bat. After this you will see that the working folder is filled with the contents of the apk. The images we need to modify are in the subfolders res/drawable-hdpi
. If you look at some of the .9.png’s in there you can see the guides (see the attached image). This makes it really easy to edit them, you can just edit them like any other image (as long as you do not touch/alter the guides).
2. Edit any images that you want. For the .9.pngs I usually make a copy without the 1 pixel border so that I can edit the entire image, then I paste the copy back into the middle of the original .9.png. You don’t have to worry about the guides, they are already set correctly.
I have created a tool that takes the stock x10 status bar icons, removes the background and sets them to a colour of your choice here. This was made to make my life easier by minimizing the time I spend in photoshop.
3. Run build.bat. This compiles the framework, embedding the guide information into the .9.png’s. The output framework is in the out folder. Do not push this to your phone as it is incomplete and the resources.arsc is stored incorrectly. If you do push it to your phone then you get to reflash
Now you can just drag the edited images out of the generated framework onto your hard drive and use steps 4. and 5. of the Drag/Drop method described below to update your framework.
Updating images using Drag/Drop
1. Open the .apk in 7zip and browse to the appropriate image folder (almost always the res\drawable-hdpi
2. Drag/Drop the images you want to edit to your hard drive. Leave the .apk open in 7zip
3. Edit the images in your favourite program (photoshop or similar)
4. Drag/Drop the images back into the .apk that is still open
5. Use the process described in the previous post to push the framework back to the phone
The reason that the .apk is left open in this process is that some (all?) of them are signed and updating them in this way doesn’t mess with the signature. I’ll admit to not being 100% sure about this, I’m sort of thinking now that people just had problems re-packing due to files being compressed that shouldn’t have been (see the section on editing XML files and adding resources to see what I mean). Please correct me on this one.
This also [almost] goes without saying, but: Make a backup
before you start (you can look at the installer for Chewitts Dark10
theme to see how to do this).
OK, now you can start messing with the appearance of your phone, have fun
Thanks to Mr_Element for the help testing this process and making it easier to follow
Thanks to damnitpud for his post here
, without which I would still have been a bit lost in draw9patch.