[TUT] How To Center The Clock On The Statusbar..And Other XML Mods As Well!

Status
Not open for further replies.

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
Isn't it for gingerbread and below only??
Or Mr.tickle already updated it to work with ics?

Personally I prefer step by step editing the code.
But it's alright to use that tool if compatible with ics already.
It's not 100% compatible with ICS just yet. Some files de- and recompile without any issues and some don't. I'm waiting for the next apktool to be released which will make it 100% compatible.

But I'm on ICS and I can use it to change my battery icon. My icons are in SystemUI.apk which is compatible. It all depends.


If you want to do it step by step, have a look at this link here: http://forum.xda-developers.com/showthread.php?t=849223

It's a bit old now, but the principle is the same. This is the method I use in Tickle My Android (more or less).
 

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
work it on 2.3?
This is the status_bar.xml from my tablet. The tablet's still on Gingerbread so your code won't be very different.

Code:
<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.StatusBarView android:background="@drawable/statusbar_background" android:orientation="vertical" android:focusable="true" android:descendantFocusability="afterDescendants"
  xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]">
    <LinearLayout android:orientation="horizontal" android:id="@id/icons" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <com.android.systemui.statusbar.IconMerger android:orientation="horizontal" android:id="@id/notificationIcons" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" android:layout_alignParentLeft="true" android:paddingLeft="6.0dip" android:gravity="center_vertical" />
        <LinearLayout android:orientation="horizontal" android:id="@id/statusIcons" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignParentRight="true" android:paddingRight="6.0dip" />
        <com.android.systemui.statusbar.Clock android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="left|center" android:paddingRight="6.0dip" android:textAppearance="@android:style/TextAppearance.StatusBar.Icon" android:singleLine="true" />
    </LinearLayout>
    <LinearLayout android:orientation="horizontal" android:id="@id/ticker" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="6.0dip" android:animationCache="false">
        <ImageSwitcher android:id="@id/tickerIcon" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="8.0dip">
            <com.android.systemui.statusbar.AnimatedImageView android:layout_width="25.0dip" android:layout_height="25.0dip" />
            <com.android.systemui.statusbar.AnimatedImageView android:layout_width="25.0dip" android:layout_height="25.0dip" />
        </ImageSwitcher>
        <com.android.systemui.statusbar.TickerView android:id="@id/tickerText" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:paddingRight="10.0dip" android:paddingTop="2.0dip">
            <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.StatusBar.Ticker" android:singleLine="true" />
            <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.StatusBar.Ticker" android:singleLine="true" />
        </com.android.systemui.statusbar.TickerView>
    </LinearLayout>
    <com.android.systemui.statusbar.DateView android:background="@drawable/statusbar_background" android:id="@id/date" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingLeft="6.0px" android:gravity="left|center" android:paddingRight="6.0px" android:textAppearance="@android:style/TextAppearance.StatusBar.Icon" android:singleLine="true" />
</com.android.systemui.statusbar.StatusBarView>
Because the clock is on its own individual line, we can move it wherever we want to. This isn't possible on Froyo because the clock is called by the same process that calls the battery and signal images.

So we apply the code suggested by serajr (I have to be honest, it's a more elegant solution) and we end up with this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.StatusBarView android:background="@drawable/statusbar_background" android:orientation="vertical" android:focusable="true" android:descendantFocusability="afterDescendants"
  xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]">
    <com.android.systemui.statusbar.Clock android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:paddingRight="6.0dip" android:textAppearance="@android:style/TextAppearance.StatusBar.Icon" android:singleLine="true" />
    <LinearLayout android:orientation="horizontal" android:id="@id/icons" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <com.android.systemui.statusbar.IconMerger android:orientation="horizontal" android:id="@id/notificationIcons" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" android:layout_alignParentLeft="true" android:paddingLeft="6.0dip" android:gravity="center_vertical" />
        <LinearLayout android:orientation="horizontal" android:id="@id/statusIcons" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignParentRight="true" android:paddingRight="6.0dip" />
    </LinearLayout>
    <LinearLayout android:orientation="horizontal" android:background="@drawable/statusbar_background" android:id="@id/ticker" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="6.0dip" android:animationCache="false">
        <ImageSwitcher android:id="@id/tickerIcon" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="8.0dip">
            <com.android.systemui.statusbar.AnimatedImageView android:layout_width="25.0dip" android:layout_height="25.0dip" />
            <com.android.systemui.statusbar.AnimatedImageView android:layout_width="25.0dip" android:layout_height="25.0dip" />
        </ImageSwitcher>
        <com.android.systemui.statusbar.TickerView android:id="@id/tickerText" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:paddingRight="10.0dip" android:paddingTop="2.0dip">
            <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.StatusBar.Ticker" android:singleLine="true" />
            <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.StatusBar.Ticker" android:singleLine="true" />
        </com.android.systemui.statusbar.TickerView>
    </LinearLayout>
    <com.android.systemui.statusbar.DateView android:background="@drawable/statusbar_background" android:id="@id/date" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingLeft="6.0px" android:gravity="left|center" android:paddingRight="6.0px" android:textAppearance="@android:style/TextAppearance.StatusBar.Icon" android:singleLine="true" />
</com.android.systemui.statusbar.StatusBarView>
And that's it! See, once you know what all this is doing, you can easily apply it to practically any rom.
 
Last edited:

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
i copy all your code into systemui from my rom and i got clock in status bar in left
Just had a look and I can see why. That'll teach me to stop doing this stuff while I'm at work!

Nah..I'll still do it..:cool:

I've updated that post with the correct code. I had the LayoutWidth as wrap_content, when it should have been fill_parent. Try it now.
 

knightazura

Senior Member
Feb 18, 2012
203
16
0
Makassar
Done. I used the same principles mentioned above and did it in a few seconds. This can be pushed back to your phone, just make sure you get the permissions right. :cool:
whooaaa~ great thanks >,< :good:
but it's still little prob bro :fingers-crossed:
the signal go left position but the clock too hehe :D

can you fix it?? thanks :eek:
 

Attachments

Last edited:
Jun 15, 2012
23
1
0
First, thanks for this tutorial. But I have this little problem:
When I reboot my phone, status bar is all black and it remains like that until I receive a notification. Can that be fixed?

Sent from my ST15i using xda premium
 

ngh55

Senior Member
Dec 8, 2007
268
27
48
Guys, I'm bleh, I can get the center clock but It moves when another signal icon pops up, and if I move it around I get the + sign in the notifications, any help will be greatly appreciated, I am posting my original status_bar.xml from CM7.

I am on EVO-4G if that matters.

EDIT: WOOT, never mind, I didn't read about the fill_parent thing, I got it working, Nice Work!!

Thank you very much.

BTW, can I do without the
Code:
android:paddingRight="6.0dip"
or what is the point of it?
 

Attachments

Last edited:

ngh55

Senior Member
Dec 8, 2007
268
27
48
I have a question, in serajr code the order is this:

Code:
<LinearLayout android:orientation="horizontal" [COLOR="Red"]android:id="@id/ticker"[/COLOR] [B]android:background="@drawable/status_bar_background"[/B]
and Ticklefish is this:

Code:
<LinearLayout android:orientation="horizontal" [B]android:background="@drawable/statusbar_background"[/B] [COLOR="red"]android:id="@id/ticker"[/COLOR]
Does the order matter?

And if I get this right you are drawing the status bar background on top of the clock so it "hides it" , am I getting this right?

I ask because I am trying to make a theme and I want to know what to do next with the status bar background drawing thing, so I can use it to my advantage.
 
  • Like
Reactions: Ticklefish

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
I have a question, in serajr code the order is this:

Code:
<LinearLayout android:orientation="horizontal" [COLOR="Red"]android:id="@id/ticker"[/COLOR] [B]android:background="@drawable/status_bar_background"[/B]
and Ticklefish is this:

Code:
<LinearLayout android:orientation="horizontal" [B]android:background="@drawable/statusbar_background"[/B] [COLOR="red"]android:id="@id/ticker"[/COLOR]
Does the order matter?

And if I get this right you are drawing the status bar background on top of the clock so it "hides it" , am I getting this right?

I ask because I am trying to make a theme and I want to know what to do next with the status bar background drawing thing, so I can use it to my advantage.
That's some very good questions!

The order of the 'android:whatever' bits doesn't matter at all. It's worth keeping the order the same in every tag, just to make it easy to read, but it really makes no difference.

And that's exactly what the code does. My solution moves the clock out of the way but the spacing would need to be adjusted for different resolutions. Serajr's code is a better way. You could try a RelativeLayout or FrameLayout to center the clock and make it move, but it's a lot of effort for a minor reward.

I'm impressed you asked about the order, well done! :)
 
  • Like
Reactions: chinittoh and ngh55

ngh55

Senior Member
Dec 8, 2007
268
27
48
Thank you very much for clarifying my doubts, I have noticed that when changing themes the status bar background gets on top of all the icons and it gets fixed after a reboot, I used serajr code so I was wondering if the issue could be fixed using your code, but as order doesn't matter like you told me there is no point compiling back my SystemUI.

{©}Sent from the Death Star{©}
 
Status
Not open for further replies.