Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,813,836 Members 41,900 Now Online
XDA Developers Android and Mobile Development Forum

[GUIDE][4.0+] Add items to Settings.apk / Change Layout

Tip us?
 
Quinny899
Old
(Last edited by Quinny899; 10th March 2013 at 01:40 PM.)
#1  
Quinny899's Avatar
Recognized Contributor - OP
Thanks Meter 3,893
Posts: 6,272
Join Date: Jan 2011
Location: Bolton le Sands, Near Lancaster, UK

 
DONATE TO ME
Default [GUIDE][4.0+] Add items to Settings.apk / Change Layout

Welcome to this mini guide of how to add items and change the layout of the Settings.apk

Each part of this guide will be rated on how hard it is for the general person. (Out of 5 stars, 5 being hardest)

So, without further ado, here we go:

Stuff You'll Need for the guide
Apktool (And therefore Java too)
A suitable Text Editor for your OS. For Windows, Notepad++ is best, for Linux I recommend Geany In this guide I will be using Geany on Ubuntu
Zipsigner on your device (for ease of use)
adb
NOTE: If you are using Linux, run everything, including apktool and your text editor/file manager as ROOT/SUDO

Do this first: Decompiling Settings.apk
Difficulty: ★★☆☆☆
1.) Open a command window in a suitable location, where apktool.jar is also located
1.) Pull your apk from your device
Code:
adb pull /system/app/Settings.apk
2.) Pull and install the framework from your device to apktool
Code:
adb pull /system/framework/framework-res.apk
Code:
java -jar apktool.jar if framework-res.apk
3.) Decompile your Settings.apk
Code:
java -jar apktool.jar d -s Settings.apk
(No source is needed)

Editing the Strings of your Settings apk
Difficulty: ★★☆☆☆
 

1.) Open a file manager and go to where the Settings has decompiled to
2.) Locate and open res/xml/settings_headers.xml in your text editor
3.) Now you can find the header you wish to edit. In this one we will change "Developer settings" to "Noobs keep out"
We need to change the string referenced in this code:
Code:
<header android:icon="@drawable/ic_settings_development" android:id="@id/development_settings" android:title="@string/development_settings_title" android:fragment="com.android.settings.DevelopmentSettings" />
The android:title reference is what we need to change, so open your Strings.xml, for your language (if it's not in there, open the default one)
Find (use Ctrl+F) the string that we earlier found, so I would search for "development_settings_title"
Code:
<string name="development_settings_title">Developer options</string>
Change the bit between the > and the < to what you want:
Code:
<string name="development_settings_title">Noobs keep out</string>
4.) Save and proceed to recompiling


Editing the Settings option's icon
Difficulty: ★★★☆☆
 

1.) Open a file manager and go to where the Settings has decompiled to
2.) Locate and open res/xml/settings_headers.xml in your text editor
3.) Locate the header you wish to change. In this one we will edit the "Development Settings" to have the "ic_settings_advanced" icon (included in CM based ROMs only)
4.) Find the header you want to edit, we want to edit this one:
Code:
<header android:icon="@drawable/ic_settings_development"  android:id="@id/development_settings"  android:title="@string/development_settings_title"  android:fragment="com.android.settings.DevelopmentSettings" />
5.) Edit the android:icon location to the icon you wish to have. The icons are in res/drawable-hdpi, mdpi, ldpi and xhdpi (depending on ROM)
We want to change it to ic_settings_advanced, so ours will look like:
Code:
<header android:icon="@drawable/ic_settings_advanced" android:id="@id/development_settings" android:title="@string/development_settings_title" android:fragment="com.android.settings.DevelopmentSettings" />
6.) If you don't want to add icons, proceed to recompiling
7.) Adding icons:
To get icons that fit, see this zip from Google: Download
i) Find the icon you wish to add, make sure it fits your screen's icon resolution (can be found with the dimension of current ic_settings icons in the apk)
ii) Copy it to the correct folder (hdpi, mdpi, xhdpi, ldpi)
iii) Name it something similar (ic_settings_<name>)
iv) Refer to it in the xml, using @drawable/ic_settings_<name>
8.) Proceed to recompiling


Adding options to the settings headers
Difficulty: ★★★★☆
 

Note: In adding settings you can open things such as GooManager for updates quickly and easily from the menu with "About phone" and "Developer settings" in it
1.) Open your decompiled settings_headers.xml
2.) Locate where you want to add an option, and add a new line:
Add this code:
Code:
<header android:icon="@drawable/ic_settings_name" android:id="@id/id" android:title="@string/title">
        <intent android:targetPackage="pkgName" android:action="android.intent.action.MAIN" android:targetClass="pkgName.Activity" />
    </header>
3.) What to change:
Change android:icon to the icon you want (for more info see "adding/changing icons")
Add a title to values/strings.xml and reference it in android:title
Change the android:targetPackage to the package name of the app you want to open. This can be found in the AndroidManifest of that particular app
Change the android:targetClass to the package name, followed by the activity you want to open, again found in that particular app's AndroidManifest
Change the android:id to an id that you can add in values/ids.xml (or delete it if you want)
4.) Proceed to recompiling


Adding dividers to settings
Difficulty: ★★★☆☆
 

Adding to the main settings screen:
1.) Open your settings_headers.xml
2.) Locate where you want to add a divider
3.) Add the following code:
Code:
<header android:id="@id/id" android:title="@string/title" />
Stuff to change:
Change the android:id to one that you added in values/ids.xml (or delete it if you want)
Change the android:title to your title in strings.xml
4.) If that's all you want, proceed to recompiling
Adding to the submenus:
1.) Open the submenu that you want to edit's xml (they're quite obvious of which one is which)
2.) Locate where you want to add a divider
3.) Add the following code:
At the start of where you want to have the divider
Code:
<PreferenceScreen android:title="@string/title" android:key="key">
Just before the next divider:
Code:
</PreferenceScreen>
Stuff to change:
Change the android:title to your title in strings.xml
Change the key to whatever you want
4.) Proceed to recompiling

Reordering Settings
Difficulty: ★★☆☆☆
 

1.) Open either the settings_headers.xml or a submenu, the process is the same
2.) Cut and paste the different options to your desired order
3.) That's all, proceed to recompiling


Adding items to submenus
Want to add a "Credits" option to your "About device" menu? This is what you need
Difficulty: ★★★☆☆
 

1.) Open your submenu xml you want (device_info_settings.xml is the about device submenu)
2.) Find your desired location of your new option and make a new line
3.) Paste the following code:
Code:
<Preference android:title="@string/title" android:key="key" android:summary="@string/summary" style="?android:preferenceInformationStyle" />
Stuff to change:
Change android:title to the title you added in values/strings.xml
Change android:key to whatever you want
Change android:summary to the longer text that you want that you added to values/strings.xml
4.) Proceed to recompiling


Bonus: Forcing "Developer settings" to be available by default on 4.2
Difficulty: ★★☆☆☆
 

1.) Open the settings_headers.xml
2.) Locate the following code:
Code:
<header android:icon="@drawable/ic_settings_development" android:id="@id/development_settings" android:title="@string/development_settings_title" android:fragment="com.android.settings.DevelopmentSettings" />
3.) Change the id from development_settings to development_settings_force
Code:
<header android:icon="@drawable/ic_settings_development"  android:id="@id/development_settings_force"  android:title="@string/development_settings_title"  android:fragment="com.android.settings.DevelopmentSettings" />
4.) Open values/ids.xml
5.) Add the following line:
Code:
<item type="id" name="development_settings_force">false</item>
6.) Proceed to recompiling


Do this last: Recompiling
Difficulty: ★★☆☆☆
1.) Re-open the command window that you used to decompile, in the same location
2.) Run the following code:
Code:
java -jar apktool.jar b Settings
3.) Push the new, unsigned apk to your device:
Code:
adb push Settings/dist/Settings.apk /sdcard/
4.) On the device, open Zipsigner and select the Settings.apk using the in/out button
5.) On the dropdown, select "platform"
6.) Press sign
7.) When it's done, run the following codes in the command window on the PC:
(Note: Some people might need to run 'adb root' first)
Code:
adb remount
Code:
adb shell cp /system/app/Settings.apk /system/app/Settings.bak
Code:
adb shell cp /sdcard/Settings-signed.apk /system/app/Settings.apk
8.) Reboot your device, you are done

Troubleshooting:
 
My apk doesn't recomplile!
Look in the command window, it should tell you where the error is, and try to fix it. If you can't, post the error log here and I/someone else will try to help

My new settings doesn't appear!
Did you sign it properly? Try that again. Else, you're out of luck

Something else is wrong!!!!1111
Leave a reply and wait, don't spam, and someone (if not me) will try to help

Screenshots for inspiration:
 


What I did:
Added an option to update, opens GooManager, using ic_action_mark from the zip from Google
Added an option that opens SuperSU, icon from the newer Settings.apk in ParanoidAndroid
Changed the title and icon of Developer Settings, as well as forcing it to always be there
Reordered the developer settings, and added different dividers

 
Devices:
Nexus 5
Galaxy Nexus
Nexus 7 FHD
Archos 80 G9
LG GT540
The Following 162 Users Say Thank You to Quinny899 For This Useful Post: [ Click to Expand ]
 
prboy1969
Old
#2  
prboy1969's Avatar
Recognized Contributor
Thanks Meter 6,818
Posts: 10,170
Join Date: May 2009
Location: Michigan
Default Re: [GUIDE][4.0+] Add items to Settings.apk / Change Layout

Nice write up

TEAM MiK
MikROMs Since 3/13/11
The Following 2 Users Say Thank You to prboy1969 For This Useful Post: [ Click to Expand ]
 
Plays2
Old
#3  
Senior Member
Thanks Meter 123
Posts: 265
Join Date: Sep 2011
Location: Peachtree City
What the heck does this mean?


Code:
Plays2s-iMac:Folder Plays2$ java -jar apktool.jar b Settings
Exception in thread "main" brut.androlib.AndrolibException: brut.directory.DirectoryException: java.util.zip.ZipException: error in opening zip file
	at brut.androlib.Androlib.readMetaFile(Androlib.java:164)
	at brut.androlib.Androlib.build(Androlib.java:183)
	at brut.androlib.Androlib.build(Androlib.java:176)
	at brut.apktool.Main.cmdBuild(Main.java:228)
	at brut.apktool.Main.main(Main.java:79)
Caused by: brut.directory.DirectoryException: java.util.zip.ZipException: error in opening zip file
	at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:55)
	at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:38)
	at brut.androlib.res.util.ExtFile.getDirectory(ExtFile.java:55)
	at brut.androlib.Androlib.readMetaFile(Androlib.java:160)
	... 4 more
Caused by: java.util.zip.ZipException: error in opening zip file
	at java.util.zip.ZipFile.open(Native Method)
	at java.util.zip.ZipFile.<init>(ZipFile.java:127)
	at java.util.zip.ZipFile.<init>(ZipFile.java:143)
	at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:53)
	... 7 more
I'm on mac btw
 
Quinny899
Old
#4  
Quinny899's Avatar
Recognized Contributor - OP
Thanks Meter 3,893
Posts: 6,272
Join Date: Jan 2011
Location: Bolton le Sands, Near Lancaster, UK

 
DONATE TO ME
Default Re: [GUIDE][4.0+] Add items to Settings.apk / Change Layout

Quote:
Originally Posted by Plays2 View Post
What the heck does this mean?


Code:
Plays2s-iMac:Folder Plays2$ java -jar apktool.jar b Settings
Exception in thread "main" brut.androlib.AndrolibException: brut.directory.DirectoryException: java.util.zip.ZipException: error in opening zip file
at brut.androlib.Androlib.readMetaFile(Androlib.java:164)
at brut.androlib.Androlib.build(Androlib.java:183)
at brut.androlib.Androlib.build(Androlib.java:176)
at brut.apktool.Main.cmdBuild(Main.java:228)
at brut.apktool.Main.main(Main.java:79)
Caused by: brut.directory.DirectoryException: java.util.zip.ZipException: error in opening zip file
at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:55)
at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:38)
at brut.androlib.res.util.ExtFile.getDirectory(ExtFile.java:55)
at brut.androlib.Androlib.readMetaFile(Androlib.java:160)
... 4 more
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:127)
at java.util.zip.ZipFile.<init>(ZipFile.java:143)
at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:53)
... 7 more
I'm on mac btw
It can't open the apk for some reason, check it's there and not corrupted

Sent from my ARCHOS 80G9 using Tapatalk HD

 
Devices:
Nexus 5
Galaxy Nexus
Nexus 7 FHD
Archos 80 G9
LG GT540
The Following 2 Users Say Thank You to Quinny899 For This Useful Post: [ Click to Expand ]
 
ruvort
Old
#5  
ruvort's Avatar
Senior Member
Thanks Meter 405
Posts: 1,498
Join Date: Aug 2010
Default Re: [GUIDE][4.0+] Add items to Settings.apk / Change Layout

This is great! Thank you for this

Huge Wallpaper Collection
 
russell664
Old
#6  
russell664's Avatar
Recognized Contributor
Thanks Meter 2,287
Posts: 1,173
Join Date: Dec 2010
Location: Somewhere you can't imagine...

 
DONATE TO ME
Hey I thought I would ask this here, i have extra options etc... in my AOSP settings. However, when I add the same strings to my HTC settings.apk, nothing ever shows up do you guys have any suggestions?

Thanks in advance.
Have A Bug with one Of my Roms? Look below on how to report them to me....

 
If you have a bug, report it with a logcat because, without one I can't do anything about it. No Logcat, Means No Fix. Do this below to get one...

Code:
adb shell dmesg ; adb logcat -b system -b radio -b events -b main


Nexus 5/ Self Compiled PAC-ROM/ Chaos Kernel V11 Nightly

 
forzaakill
Old
#7  
Junior Member
Thanks Meter 0
Posts: 2
Join Date: Jun 2012
Code:
C:\Users\Hakan\Desktop\android compile\esas>java -jar apktool.jar b Settings
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.Androl
ibException: brut.common.BrutException: could not exec command: [aapt, p, --min-
sdk-version, 15, --target-sdk-version, 15, -F, C:\Users\Hakan\AppData\Local\Temp
\APKTOOL4787001507934327803.tmp, -0, arsc, -I, C:\Users\Hakan\apktool\framework\
1.apk, -S, C:\Users\Hakan\Desktop\android compile\esas\Settings\res, -M, C:\User
s\Hakan\Desktop\android compile\esas\Settings\AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:358)
        at brut.androlib.Androlib.buildResources(Androlib.java:283)
        at brut.androlib.Androlib.build(Androlib.java:206)
        at brut.androlib.Androlib.build(Androlib.java:176)
        at brut.apktool.Main.cmdBuild(Main.java:228)
        at brut.apktool.Main.main(Main.java:79)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not
 exec command: [aapt, p, --min-sdk-version, 15, --target-sdk-version, 15, -F, C:
\Users\Hakan\AppData\Local\Temp\APKTOOL4787001507934327803.tmp, -0, arsc, -I, C:
\Users\Hakan\apktool\framework\1.apk, -S, C:\Users\Hakan\Desktop\android compile
\esas\Settings\res, -M, C:\Users\Hakan\Desktop\android compile\esas\Settings\And
roidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:357)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:336)
        ... 5 more
Caused by: brut.common.BrutException: could not exec command: [aapt, p, --min-sd
k-version, 15, --target-sdk-version, 15, -F, C:\Users\Hakan\AppData\Local\Temp\A
PKTOOL4787001507934327803.tmp, -0, arsc, -I, C:\Users\Hakan\apktool\framework\1.
apk, -S, C:\Users\Hakan\Desktop\android compile\esas\Settings\res, -M, C:\Users\
Hakan\Desktop\android compile\esas\Settings\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:93)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:355)
        ... 6 more
Caused by: java.io.IOException: Cannot run program "aapt": CreateProcess error=2
, Sistem belirtilen dosyay? bulam?yor
        at java.lang.ProcessBuilder.start(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at brut.util.OS.exec(OS.java:84)
        ... 7 more
Caused by: java.io.IOException: CreateProcess error=2, Sistem belirtilen dosyay?
 bulam?yor
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        ... 11 more

C:\Users\Hakan\Desktop\android compile\esas>

Means system cant find the file in English. What should I do?
 
Diaz1999
Old
#8  
Diaz1999's Avatar
Senior Member
Thanks Meter 565
Posts: 643
Join Date: Oct 2012
Location: nullPointerException(.surabaya)

 
DONATE TO ME
Quote:
Originally Posted by forzaakill View Post
Code:
C:\Users\Hakan\Desktop\android compile\esas>java -jar apktool.jar b Settings
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.Androl
ibException: brut.common.BrutException: could not exec command: [aapt, p, --min-
sdk-version, 15, --target-sdk-version, 15, -F, C:\Users\Hakan\AppData\Local\Temp
\APKTOOL4787001507934327803.tmp, -0, arsc, -I, C:\Users\Hakan\apktool\framework\
1.apk, -S, C:\Users\Hakan\Desktop\android compile\esas\Settings\res, -M, C:\User
s\Hakan\Desktop\android compile\esas\Settings\AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:358)
        at brut.androlib.Androlib.buildResources(Androlib.java:283)
        at brut.androlib.Androlib.build(Androlib.java:206)
        at brut.androlib.Androlib.build(Androlib.java:176)
        at brut.apktool.Main.cmdBuild(Main.java:228)
        at brut.apktool.Main.main(Main.java:79)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not
 exec command: [aapt, p, --min-sdk-version, 15, --target-sdk-version, 15, -F, C:
\Users\Hakan\AppData\Local\Temp\APKTOOL4787001507934327803.tmp, -0, arsc, -I, C:
\Users\Hakan\apktool\framework\1.apk, -S, C:\Users\Hakan\Desktop\android compile
\esas\Settings\res, -M, C:\Users\Hakan\Desktop\android compile\esas\Settings\And
roidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:357)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:336)
        ... 5 more
Caused by: brut.common.BrutException: could not exec command: [aapt, p, --min-sd
k-version, 15, --target-sdk-version, 15, -F, C:\Users\Hakan\AppData\Local\Temp\A
PKTOOL4787001507934327803.tmp, -0, arsc, -I, C:\Users\Hakan\apktool\framework\1.
apk, -S, C:\Users\Hakan\Desktop\android compile\esas\Settings\res, -M, C:\Users\
Hakan\Desktop\android compile\esas\Settings\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:93)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:355)
        ... 6 more
Caused by: java.io.IOException: Cannot run program "aapt": CreateProcess error=2
, Sistem belirtilen dosyay? bulam?yor
        at java.lang.ProcessBuilder.start(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at brut.util.OS.exec(OS.java:84)
        ... 7 more
Caused by: java.io.IOException: CreateProcess error=2, Sistem belirtilen dosyay?
 bulam?yor
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        ... 11 more

C:\Users\Hakan\Desktop\android compile\esas>

Means system cant find the file in English. What should I do?
I thought that's your aapt is error
Helpful post?

Quote:
Originally Posted by C.Hatfield View Post
IT AIN'T THERE.

Sent from my Galaxy Nexus using Tapatalk 4 Beta
 
Diaz1999
Old
#9  
Diaz1999's Avatar
Senior Member
Thanks Meter 565
Posts: 643
Join Date: Oct 2012
Location: nullPointerException(.surabaya)

 
DONATE TO ME
@OP, here's what I've done

Anyway big thanks to you, sometimes pressing Thanks button it not enough

via XDA for Timescape™
Attached Thumbnails
Click image for larger version

Name:	uploadfromtaptalk1367780352962.jpg
Views:	4466
Size:	22.8 KB
ID:	1938267   Click image for larger version

Name:	uploadfromtaptalk1367780374772.jpg
Views:	4156
Size:	21.0 KB
ID:	1938269   Click image for larger version

Name:	uploadfromtaptalk1367780588909.jpg
Views:	4012
Size:	23.8 KB
ID:	1938273  
Helpful post?

Quote:
Originally Posted by C.Hatfield View Post
IT AIN'T THERE.

Sent from my Galaxy Nexus using Tapatalk 4 Beta
The Following 3 Users Say Thank You to Diaz1999 For This Useful Post: [ Click to Expand ]
 
Quinny899
Old
#10  
Quinny899's Avatar
Recognized Contributor - OP
Thanks Meter 3,893
Posts: 6,272
Join Date: Jan 2011
Location: Bolton le Sands, Near Lancaster, UK

 
DONATE TO ME
Quote:
Originally Posted by Diaz1999 View Post
@OP, here's what I've done

Anyway big thanks to you, sometimes pressing Thanks button it not enough

via XDA for Timescape™
Very nice

Sent from my Archos G9 using Tapatalk HD

 
Devices:
Nexus 5
Galaxy Nexus
Nexus 7 FHD
Archos 80 G9
LG GT540

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes