[Sony Cross-Device Development Themes and Apps] Ticklefish:
​

How would you like to add more buttons to your navbar without cluttering it up? Well, with my Scrolling Navbar mod, now you can!

To do this mod, you'll need to decompile your SystemUI.apk. There are many ways to do this but I always recommend using Tickle My Android (http://xdaforums.com/showthread.php?t=1633333). It's fast, it's free, it's easy-to-use and the developer is an incredibly handsome human being...:rolleyes:

Anyway, however you do it, once you've decompiled your SystemUI.apk you'll need to edit your "res/layout/navigation_bar.xml". That'll look something like this (I've excluded some of the lines so this post was originally longer than xda allows..):

<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.phone.NavigationBarView android:background="@drawable/system_bar_background" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res-auto">
<FrameLayout android:id="@id/rot0" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal" android:id="@id/nav_buttons" android:clipChildren="false" android:clipToPadding="false" android:layout_width="720.0px" android:layout_height="fill_parent" android:animateLayoutChanges="true">
<View android:visibility="invisible" android:layout_width="@dimen/navigation_side_padding" android:layout_height="fill_parent" android:layout_weight="0.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/back" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_back" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_back" android:layout_marginStart="@dimen/navigation_key_outer_margin" systemui:keyCode="4" />
<View android:visibility="invisible" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/home" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_home" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_home" systemui:keyCode="3" systemui:keyRepeat="false" />
<View android:visibility="invisible" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/recent_apps" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_recent" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_recent" android:layout_marginEnd="@dimen/navigation_key_outer_margin" />
<FrameLayout android:layout_width="@dimen/navigation_side_padding" android:layout_height="fill_parent" android:layout_weight="0.0">
<com.android.systemui.statusbar.policy.KeyButtonView android:layout_gravity="end" android:id="@id/menu" android:visibility="invisible" android:layout_width="@dimen/navigation_extra_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_menu" android:scaleType="centerInside" android:contentDescription="@string/accessibility_menu" systemui:keyCode="82" />
<com.android.systemui.statusbar.policy.KeyButtonView android:layout_gravity="end" android:id="@id/ime_switcher" android:visibility="invisible" android:layout_width="@dimen/navigation_extra_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_ime_switcher_default" android:scaleType="centerInside" android:contentDescription="@string/accessibility_ime_switch_button" />
</FrameLayout>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:id="@id/lights_out" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@id/back_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_back" android:layout_marginStart="@dimen/navigation_key_outer_margin_lights_out" />
<View android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />
<ImageView android:id="@id/home_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_large" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_home" />
<View android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />
<ImageView android:id="@id/recent_apps_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_recent" android:layout_marginEnd="@dimen/navigation_key_outer_margin_lights_out" />
</LinearLayout>
<com.android.systemui.statusbar.policy.DeadZone android:layout_gravity="top" android:id="@id/deadzone" android:layout_width="fill_parent" android:layout_height="fill_parent" systemui:minSize="@dimen/navigation_bar_deadzone_size" systemui:maxSize="@dimen/navigation_bar_deadzone_size_max" systemui:holdTime="@integer/navigation_bar_deadzone_hold" systemui:decayTime="@integer/navigation_bar_deadzone_decay" systemui:orientation="horizontal" />
</FrameLayout>
.....
.....
</com.android.systemui.statusbar.phone.NavigationBarView>

This is the XML from a stock Marshmallow rom on my Sony Xperia Z3 Compact. In theory though, this mod should work on any device running Cupcake or up that has a navbar.

What we need to do is add some lines to that first FrameLayout to create what's known as a "HorizontalScrollView":

<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.phone.NavigationBarView android:background="@drawable/system_bar_background" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res-auto">
<FrameLayout android:id="@id/rot0" android:layout_width="fill_parent" android:layout_height="fill_parent">
[COLOR=red]<HorizontalScrollView android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="wrap_content">[/COLOR]
[COLOR=red][/COLOR][COLOR=red] <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">[/COLOR]
<LinearLayout android:orientation="horizontal" android:id="@id/nav_buttons" android:clipChildren="false" android:clipToPadding="false" android:layout_width="fill_parent" android:layout_height="fill_parent" android:animateLayoutChanges="true">
<View android:visibility="invisible" android:layout_width="@dimen/navigation_side_padding" android:layout_height="fill_parent" android:layout_weight="0.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/back" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_back" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_back" android:layout_marginStart="@dimen/navigation_key_outer_margin" systemui:keyCode="4" />
<View android:visibility="invisible" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/home" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_home" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_home" systemui:keyCode="3" systemui:keyRepeat="false" />
<View android:visibility="invisible" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/recent_apps" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_recent" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_recent" android:layout_marginEnd="@dimen/navigation_key_outer_margin" />
<FrameLayout android:layout_width="@dimen/navigation_side_padding" android:layout_height="fill_parent" android:layout_weight="0.0">
<com.android.systemui.statusbar.policy.KeyButtonView android:layout_gravity="end" android:id="@id/menu" android:visibility="invisible" android:layout_width="@dimen/navigation_extra_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_menu" android:scaleType="centerInside" android:contentDescription="@string/accessibility_menu" systemui:keyCode="82" />
<com.android.systemui.statusbar.policy.KeyButtonView android:layout_gravity="end" android:id="@id/ime_switcher" android:visibility="invisible" android:layout_width="@dimen/navigation_extra_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_ime_switcher_default" android:scaleType="centerInside" android:contentDescription="@string/accessibility_ime_switch_button" />
</FrameLayout>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:id="@id/lights_out" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@id/back_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_back" android:layout_marginStart="@dimen/navigation_key_outer_margin_lights_out" />
<View android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />
<ImageView android:id="@id/home_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_large" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_home" />
<View android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />
<ImageView android:id="@id/recent_apps_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_recent" android:layout_marginEnd="@dimen/navigation_key_outer_margin_lights_out" />
</LinearLayout>
[COLOR=red] </LinearLayout>[/COLOR]
[COLOR=red][/COLOR][COLOR=red] </HorizontalScrollView>[/COLOR]
</FrameLayout>
.....
.....
</com.android.systemui.statusbar.phone.NavigationBarView>

Next we need to add some "keycodes". We already have some of those for the "back", "home" and "recent" buttons. But there are a lot more we can use (have a look here for the full list: https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_0).

For this mod I've chosen to use keycodes which can launch the music player, camera and dialer apps as well as music controls and cursor controls (very handy when writing lots of text). I've also put a power button in as well. You don't have to use these if you don't want to. You don't even have to have them in the same order, it's entirely up to you. Feel free to experiment.

For now let's add those extra lines:

<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.phone.NavigationBarView android:background="@drawable/system_bar_background" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res-auto">
<FrameLayout android:id="@id/rot0" android:layout_width="fill_parent" android:layout_height="fill_parent">
<HorizontalScrollView android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal" android:id="@id/nav_buttons" android:clipChildren="false" android:clipToPadding="false" android:layout_width="fill_parent" android:layout_height="fill_parent" android:animateLayoutChanges="true">
<View android:visibility="invisible" android:layout_width="@dimen/navigation_side_padding" android:layout_height="fill_parent" android:layout_weight="0.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/back" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_back" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_back" android:layout_marginStart="@dimen/navigation_key_outer_margin" systemui:keyCode="4" />
<View android:visibility="invisible" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/home" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_home" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_home" systemui:keyCode="3" systemui:keyRepeat="false" />
<View android:visibility="invisible" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@id/recent_apps" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_recent" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_recent" android:layout_marginEnd="@dimen/navigation_key_outer_margin" />
<FrameLayout android:layout_width="@dimen/navigation_side_padding" android:layout_height="fill_parent" android:layout_weight="0.0">
<com.android.systemui.statusbar.policy.KeyButtonView android:layout_gravity="end" android:id="@id/menu" android:visibility="invisible" android:layout_width="@dimen/navigation_extra_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_menu" android:scaleType="centerInside" android:contentDescription="@string/accessibility_menu" systemui:keyCode="82" />
<com.android.systemui.statusbar.policy.KeyButtonView android:layout_gravity="end" android:id="@id/ime_switcher" android:visibility="invisible" android:layout_width="@dimen/navigation_extra_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_ime_switcher_default" android:scaleType="centerInside" android:contentDescription="@string/accessibility_ime_switch_button" />
</FrameLayout>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:id="@id/lights_out" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@id/back_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_back" android:layout_marginStart="@dimen/navigation_key_outer_margin_lights_out" />
<View android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />
<ImageView android:id="@id/home_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_large" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_home" />
<View android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />
<ImageView android:id="@id/recent_apps_lights_out" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" android:layout_weight="0.0" android:contentDescription="@string/accessibility_recent" android:layout_marginEnd="@dimen/navigation_key_outer_margin_lights_out" />
</LinearLayout>
[color="red"] <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModDown" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/downwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="20" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModLeft" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/leftwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="21" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModRight" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/rightwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="22" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModUp" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/upwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="19" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModCamera" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/camerawhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="27" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModCall" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/phonewhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="5" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModMusic" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/musicwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="209" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModBackTrack" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/backwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="88" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModPlayPause" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/playwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="85" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModForwardTrack" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/forwardwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="87" />
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/ModPower" android:layout_width="@dimen/navigation_key_width" android:layout_height="fill_parent" android:src="@drawable/powerwhite" android:scaleType="center" android:layout_weight="0.0" android:layout_marginEnd="@dimen/navigation_key_outer_margin" systemui:keyCode="26" />[/color]
<com.android.systemui.statusbar.policy.DeadZone android:layout_gravity="top" android:id="@id/deadzone" android:layout_width="fill_parent" android:layout_height="fill_parent" systemui:minSize="@dimen/navigation_bar_deadzone_size" systemui:maxSize="@dimen/navigation_bar_deadzone_size_max" systemui:holdTime="@integer/navigation_bar_deadzone_hold" systemui:decayTime="@integer/navigation_bar_deadzone_decay" systemui:orientation="horizontal" />
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
.....
.....
</com.android.systemui.statusbar.phone.NavigationBarView>

So far so good. Now download the attached ZIP file, unzip it and place the image files into the relevant "drawable-*dpi" folder. My phone is a XHDPI device so that's the folder they went into in my APK. These are standard PNG files I found on the internet so you're welcome to change them if you don't like them. Just keep the filenames the same!

You also need to change the "layout_width" of the first "@id/nav_buttons" Layout. This needs to be done to space everything out properly. The layout_width

must

be the same width in pixels as your phone. My phone has a resolution of 720x1280 so I need to change the layout_width from "fill_parent" to "720px".

So I'd change:

<LinearLayout android:orientation="horizontal" android:id="@id/nav_buttons" android:clipChildren="false" android:clipToPadding="false" android:layout_width="fill_parent" android:layout_height="fill_parent" android:animateLayoutChanges="true">

to:

<LinearLayout android:orientation="horizontal" android:id="@id/nav_buttons" android:clipChildren="false" android:clipToPadding="false" [COLOR="red"]android:layout_width="720.0px"[/COLOR] android:layout_height="fill_parent" android:animateLayoutChanges="true">

And that's it. Recompile and flash back to your phone as normal. Once the phone reboots you should have a nice, new, scrolling navbar!!

(My thanks go to [MENTION=2948558]Spannaa[/MENTION], [MENTION=3989065]serajr[/MENTION], [MENTION=3862405]SpaceCaker[/MENTION] and [MENTION=5888332]xenreon[/MENTION] for their help in getting this mod finally working. :highfive:)