Introduction
Remember a time when an unthemed popup popped up in an app, and you tried all that you could to change the colors of it, then found out it wasn't even in the app you spent hours on at the first place? Damn right I do!!! Wasted so much of my youth looking for things in the wrong place.
In this guide I will be going over a desktop application called "Android Device Monitor", and how to use it for theming. This program is not bound to theming, as it can help many ROM developers like locating a CP'd commit and forgot where to set a textColor was set in a dialog. For example: https://github.com/TeamBliss-LP/and...mmit/4f85ee62ab0db9d2a78b1bfeee32dfa17313e215.
The guide will also outline other methods to locate hardcoded colors on most apps, and this is not bounded by device. This will theoretically work on any device running Android, as long as you enable USB debugging on your device. So it should theoretically work on TouchWiz, AOSP, CM, Sense, LG Home, XperiaHome, etc...
Most importantly, if your friend comes over with a non-rooted phone, fret not, this DOES NOT require root. So! If you happen to stumble here from a link I requested you to follow, I'll assume you're either a themer, or you're a user of a theme. For users, this guide would be used to aid the themer when the themer does not have access to what you are seeing in an app due to differences in software/region bound software/firmware versions/custom ROMs. For themers, I hav known about this trick for a while but haven't gotten the time to write it - but this saves me precious time solving "unsolvable" issues, like during the days when we didn't have Setting's dashboard exposed (before the January 27th commit).
To understand how this works, we have to understand how Android system works. We can change many colors through colors.xml, but styles, layouts and java can also change colors. We have to remember this structure. Left is greater than the corresponding right.
Java > Layout > Styles > Colors
In this guide, I will be focusing on using ADM to locate colors/usages of resources within Layouts, thus allowing you to locate things within styles/colors.
ATTENTION
This guide is NOT 100% guaranteed.
As many third party apps like Google+ designs it's layout through the java, and the overall code of the application. Using Android Device Monitor, it is the first steps of beginning to theme.
This guide is meant to be a STARTING GROUND when you face any issue. I cannot guarantee any success, but this has helped me find out whether many things are hardcoded or not. So having this as a utility will greatly help a lot of people new to theming!
I also do NOT have access to a TW/Sense/LG Home/XH device, so if you have any issues (non-connection issues) with using ADM to trace your screen, please tell me. But theoretically, this should work on any device.
What is Android Device Monitor?
Android Device Monitor is a desktop application that traces the running programs of your device connected to your PC. You can use this to debug as it shows many useful information.
But for this guide, I will use it to show how to use it to take a screenshot XML dump of your phone's screen, and you can mouseover the elements of your screenshot on your screen to locate the layout of the app, or whatever is on your screen.
Wow! That sounds cool! How do I get it?
All you have to do is install the Android Studio package from Google, and you will get it preinstalled with it.
You can download Android Studio from this link: http://developer.android.com/sdk/index.html?gclid=CLWt6IX99MgCFRCpaQodrhwHng
Make sure you install the prerequisite packages once installing and setting up Android Studio. This includes the complete SDK.
If you would like to install just the SDK, that is possible too: https://developer.android.com/sdk/installing/index.html?pkg=tools
Make sure you install Android SDK Tools in the SDK Manager. Android Studio method is recommended as it comes with everything pre-installed once setting everything up.
Let's get started, shall we?
(*) Make sure you have installed adb/fastboot on your computer prior to continuing: http://xdaforums.com/showthread.php?p=48915118
A great text editing tool is Notepad++, available here: https://notepad-plus-plus.org/
ON YOUR PHONE/TABLET
I will be using a Lollipop based CM ROM in this tutorial. Keep your device unplugged at this point.
ON YOUR COMPUTER
You will then see a table on the bottom right identifying all its attributes. But most importantly, you will want to see that it is actually in package ID com.google.android.gms (Google Play Services), so you must invert that/theme that.
You can see how the table above told me that the package ID was com.google.android.gms, and thus I was able to go find it in the decompiled APK of Google Play Services.
Also to note, resource-id is also a great way to start, as it tells you the app's layout object ID, which allows you to find it within the app's res/layout folder by using Notepad++ and the Find in Files section. If by any chance, you get no information at all, you should check the structure of the app on the top right, and locate within layouts folder as well. For example, if you see a FrameLayout and textView x2, you have identified the structure of the activity fragment of the app, and it MAY help you for layouts.
In my commit at the beginning of this thread, I was locating an unthemed black text in a dialog, and found out that the dialog's resource-id was "dpi_edit", so I searched in res/layout using N++'s Find in Files tool and found out that it was in this file: https://github.com/TeamBliss-LP/and...13e215/res/layout/alert_dialog_text_entry.xml. So I made the change to the textColor and pushed the commit to the source. Thus allowing users to have a visible DPI text color, even though we expected that the ?attr should work.
Demonstration on how to reverse locate a specific color
Troubleshooting
Q: There is an error every time I launch ADM again! What should I do?
A: The error is normal, just press OK and proceed. (This error in spoiler, if any others, message below)
Q: I keep getting a permission error with my device when I click the button and it doesn't draw my screenshot!
A: This happens when your device is extremely "dirty", a complete clean flash is required. In my case, I fastbooted stock and reflashed my custom ROM. You can try wiping data, as the permissions lie somewhere there.
Q: I still can't get my theme to theme the hardcoded thing, help!
A: As I said, this doesn't work for all cases, this is only a starting and ending ground to see if it is themable. If you can't find out what to do, then chances are you did everything you can!
Q: Any other tips?
A: If you really can't find it, but you have a specific color you want to get rid of, try using Photoshop's Eyedropper tool to pick out the color from the screenshot, then use Notepad++ to search for this color. You should find the hex from the color by clicking the color palette.
Q: What about using backgroundTint?
A: You can use this to target many white hardcoded (definite) backgrounds by adding a backgroundTint attribute, but this may affect other things, like the Paste tooltip will take on this backgroundTint thus you can't read the "Paste" text. But definitely, this is a great way to start targeting white backgrounds!
Q: I have more questions!
A: Post in the thread and tag me using @nicholaschum, I'm more likely to check if I get a notification.
XDA:DevDB Information
[GUIDE] Locating hidden values, random dialogs and hardcodes (AOSP/TW/Sense/XH), Theme for all devices (see above for details)
Contributors
nicholaschum
Version Information
Status: Stable
Created 2015-11-03
Last Updated 2015-11-06
Remember a time when an unthemed popup popped up in an app, and you tried all that you could to change the colors of it, then found out it wasn't even in the app you spent hours on at the first place? Damn right I do!!! Wasted so much of my youth looking for things in the wrong place.
In this guide I will be going over a desktop application called "Android Device Monitor", and how to use it for theming. This program is not bound to theming, as it can help many ROM developers like locating a CP'd commit and forgot where to set a textColor was set in a dialog. For example: https://github.com/TeamBliss-LP/and...mmit/4f85ee62ab0db9d2a78b1bfeee32dfa17313e215.
The guide will also outline other methods to locate hardcoded colors on most apps, and this is not bounded by device. This will theoretically work on any device running Android, as long as you enable USB debugging on your device. So it should theoretically work on TouchWiz, AOSP, CM, Sense, LG Home, XperiaHome, etc...
Most importantly, if your friend comes over with a non-rooted phone, fret not, this DOES NOT require root. So! If you happen to stumble here from a link I requested you to follow, I'll assume you're either a themer, or you're a user of a theme. For users, this guide would be used to aid the themer when the themer does not have access to what you are seeing in an app due to differences in software/region bound software/firmware versions/custom ROMs. For themers, I hav known about this trick for a while but haven't gotten the time to write it - but this saves me precious time solving "unsolvable" issues, like during the days when we didn't have Setting's dashboard exposed (before the January 27th commit).
To understand how this works, we have to understand how Android system works. We can change many colors through colors.xml, but styles, layouts and java can also change colors. We have to remember this structure. Left is greater than the corresponding right.
Java > Layout > Styles > Colors
In this guide, I will be focusing on using ADM to locate colors/usages of resources within Layouts, thus allowing you to locate things within styles/colors.
ATTENTION
This guide is NOT 100% guaranteed.
As many third party apps like Google+ designs it's layout through the java, and the overall code of the application. Using Android Device Monitor, it is the first steps of beginning to theme.
This guide is meant to be a STARTING GROUND when you face any issue. I cannot guarantee any success, but this has helped me find out whether many things are hardcoded or not. So having this as a utility will greatly help a lot of people new to theming!
I also do NOT have access to a TW/Sense/LG Home/XH device, so if you have any issues (non-connection issues) with using ADM to trace your screen, please tell me. But theoretically, this should work on any device.
What is Android Device Monitor?
Android Device Monitor is a desktop application that traces the running programs of your device connected to your PC. You can use this to debug as it shows many useful information.
But for this guide, I will use it to show how to use it to take a screenshot XML dump of your phone's screen, and you can mouseover the elements of your screenshot on your screen to locate the layout of the app, or whatever is on your screen.
Wow! That sounds cool! How do I get it?
All you have to do is install the Android Studio package from Google, and you will get it preinstalled with it.
You can download Android Studio from this link: http://developer.android.com/sdk/index.html?gclid=CLWt6IX99MgCFRCpaQodrhwHng
Make sure you install the prerequisite packages once installing and setting up Android Studio. This includes the complete SDK.
If you would like to install just the SDK, that is possible too: https://developer.android.com/sdk/installing/index.html?pkg=tools
Make sure you install Android SDK Tools in the SDK Manager. Android Studio method is recommended as it comes with everything pre-installed once setting everything up.
Let's get started, shall we?
(*) Make sure you have installed adb/fastboot on your computer prior to continuing: http://xdaforums.com/showthread.php?p=48915118
A great text editing tool is Notepad++, available here: https://notepad-plus-plus.org/
ON YOUR PHONE/TABLET
I will be using a Lollipop based CM ROM in this tutorial. Keep your device unplugged at this point.
- First you have to enable Developer Options by going into About Device in Settings, then clicking the Build number 7 times. This enables Developer Options directly in the main menu of Settings.
- Once activated, go into Developer Options
- Scroll down until you see Android debugging, then activate that.
- Plug your phone into the computer
- At this point, a popup will appear on your device to verify the RSA fingerprint of your computer. Click Always Allow from this Computer.
- ATTENTION: If you did not get a popup, adb is NOT installed correctly/your phone is not detected in ADB mode, or your computer does not have it set up properly. Follow my link above to get it set up quicker than using Android Studio's method. (*)
- Once you agreed to the popup, then go to the screen where you want to see what the problem is. For example, you want to find out why there is a random white dialog when toggling GPS telling you to improve location accuracy.
- Keep the screen turned on/turn on Stay Awake in Developer Options so it will keep your phone awake while plugged in. After this step, you have successfully finished using your phone.
ON YOUR COMPUTER
- ATTENTION: If you already use Android Studio to build your theme, you can skip steps 2 and 3. Also to note, you can always use search and locate the "monitor.exe" file in your Android Studio directory, but that is too fussy, as it likes to error out a lot.
- Open Android Studio, and create a new project, you need to Start a new Android Studio Project, follow all the steps till you click Finish.
- You may or may not be greeted with a couple of popups, just dismiss them.
- Once you get to a window with an available toolbar, click on Tools -> Android -> Android Device Monitor.
- ATTENTION: If you're running Android Studio 1.4.1 and above, click on the icon in the toolbar.
- On first launch you will get this popup, click Proceed
- Your phone will appear on the left, including all the processes and background services running on your phone.
- Click on your device, and click on the Dump View Hierarchy for UI Automator icon, an icon that should be next to the camera, with three stacked phones.
- At this point, the computer will dump whatever is on your screen, if your screen is off, it will dump a black screen, so you should have kept it awake.
- Once complete, you will want to hover over the unidentifiable object on your screen. So if the white dialog (as mentioned previously) when toggling location is a bother, we hover over the screen's focused dialog, and click on it. When selected, the area has a red rectangle.
You will then see a table on the bottom right identifying all its attributes. But most importantly, you will want to see that it is actually in package ID com.google.android.gms (Google Play Services), so you must invert that/theme that.
You can see how the table above told me that the package ID was com.google.android.gms, and thus I was able to go find it in the decompiled APK of Google Play Services.
Also to note, resource-id is also a great way to start, as it tells you the app's layout object ID, which allows you to find it within the app's res/layout folder by using Notepad++ and the Find in Files section. If by any chance, you get no information at all, you should check the structure of the app on the top right, and locate within layouts folder as well. For example, if you see a FrameLayout and textView x2, you have identified the structure of the activity fragment of the app, and it MAY help you for layouts.
In my commit at the beginning of this thread, I was locating an unthemed black text in a dialog, and found out that the dialog's resource-id was "dpi_edit", so I searched in res/layout using N++'s Find in Files tool and found out that it was in this file: https://github.com/TeamBliss-LP/and...13e215/res/layout/alert_dialog_text_entry.xml. So I made the change to the textColor and pushed the commit to the source. Thus allowing users to have a visible DPI text color, even though we expected that the ?attr should work.
Demonstration on how to reverse locate a specific color
- Let's find something specific using this trace method, so for example, I would like to find the background of the switch bar in Settings. Pretend I don't know how. So following my above steps, I'm able to reach this:
- We see that under resource-id in the Node Detail box, it says: com.android.settings:id/switch_bar -- so we should search for switch_bar under res/layouts of com.android.settings (your decompiled settings).....
- We go into Notepad++, and use the Find in Files feature (Search -> Find in Files) and type in the resource-id after ":id/", which is "switch_bar"
- Click Find All and wait for it to finish. Afterwards, you will get a list of results with a hit. In this case, we have one result.
- Double click on the result, and you will be greeted with a layout XML with the ID. In the XML you will see that you have a bunch of stuff there, so with some smarts and some logic on the same line, you can see if the background is set to a hardcoded hex (hardcoded meaning there's a hex code there, as you can't modify layouts in CMTE, or is it rerouted to another color)
- We can see that the background was linked to a color variable, "switchbar_background", now change that in com.android.settings/res/values/colors.xml, then you tell me if I'm correct If you see something else in there, or are a ROM developer and trying to expose some values, replace the hardcoded hex to a rerouted color in the corresponding app's colors.xml, and you have successfully exposed it!
Troubleshooting
Q: There is an error every time I launch ADM again! What should I do?
A: The error is normal, just press OK and proceed. (This error in spoiler, if any others, message below)
Q: I keep getting a permission error with my device when I click the button and it doesn't draw my screenshot!
A: This happens when your device is extremely "dirty", a complete clean flash is required. In my case, I fastbooted stock and reflashed my custom ROM. You can try wiping data, as the permissions lie somewhere there.
Q: I still can't get my theme to theme the hardcoded thing, help!
A: As I said, this doesn't work for all cases, this is only a starting and ending ground to see if it is themable. If you can't find out what to do, then chances are you did everything you can!
Q: Any other tips?
A: If you really can't find it, but you have a specific color you want to get rid of, try using Photoshop's Eyedropper tool to pick out the color from the screenshot, then use Notepad++ to search for this color. You should find the hex from the color by clicking the color palette.
Q: What about using backgroundTint?
A: You can use this to target many white hardcoded (definite) backgrounds by adding a backgroundTint attribute, but this may affect other things, like the Paste tooltip will take on this backgroundTint thus you can't read the "Paste" text. But definitely, this is a great way to start targeting white backgrounds!
Q: I have more questions!
A: Post in the thread and tag me using @nicholaschum, I'm more likely to check if I get a notification.
XDA:DevDB Information
[GUIDE] Locating hidden values, random dialogs and hardcodes (AOSP/TW/Sense/XH), Theme for all devices (see above for details)
Contributors
nicholaschum
Version Information
Status: Stable
Created 2015-11-03
Last Updated 2015-11-06