Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,730,761 Members 42,205 Now Online
XDA Developers Android and Mobile Development Forum

[GUIDE][HOW-TO] Extended ActionBar

Tip us?
 
Takhion
Old
(Last edited by eagleeyetom; 31st January 2014 at 07:39 PM.) Reason: Link added
#1  
Takhion's Avatar
Junior Member - OP
Thanks Meter 30
Posts: 18
Join Date: May 2011
Default [GUIDE][HOW-TO] Extended ActionBar

https://github.com/Takhion/android-extendedactionbar

The problem:

Android 4.4 Kitkat introduced a wonderful new opportunity: translucent bars.

It's as simple as adding the following to your theme:

Code:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
Awesome, right? Well, almost.
The thing is, if you happen to have an ActionBar (like 99.9% of apps out there) than it won't automatically extend behind the status bar: the status bar will be translucent and the window background will be showed...
A picture is worth a thousand words:

Click image for larger version

Name:	problem.png
Views:	4181
Size:	47.4 KB
ID:	2550838

There are many ways to fix this programmatically or with some wise layouts, but when the application is launched or recreated only the theme will be used (before loading ANY code or layout) and the problem will still be annoyingly present.

The solution:

In the repository at the end I show how to achieve an illusion of "ActionBar extension" (look at the code to see what it means). It is unfortunately more of a hack than a proper solution, but that is due to the fact that the required components (namely @android:dimen/status_bar_height and the ability to create custom drawables, as the ones provided are barely usable and highly bugged) have been banned by the Gods.

Please use it with careful consideration and don't blame me if your device explodes or you cat conquers the world!

Click image for larger version

Name:	solution.png
Views:	3433
Size:	46.3 KB
ID:	2550839

The extra mile:

While I was there I took the opportunity to create a simple Activity that removes the hacky window background and does things properly in order to eliminate any overdraw.
It's supposed to be a starting point, though I hope to make it into a real library someday.

Before:

Click image for larger version

Name:	overdraw_before.png
Views:	3707
Size:	47.6 KB
ID:	2550840

After:

Click image for larger version

Name:	overdraw_after.png
Views:	3704
Size:	47.0 KB
ID:	2550841

Notes:

I will start using a variation of this code in my apps along with a "secret agent" that will notify me if it ever encounters a device with a status bar bigger than 25dp (if it's smaller or not at the top, it won't be a problem as it will get drawn behind the ActionBar).
If such a thing happens, I will update this accordingly.


https://github.com/Takhion/android-extendedactionbar
The Following 22 Users Say Thank You to Takhion For This Useful Post: [ Click to Expand ]
 
tiwiz
Old
#2  
tiwiz's Avatar
Recognized Developer
Thanks Meter 83
Posts: 266
Join Date: Nov 2010
Location: Torino

 
DONATE TO ME
Great job, Takhion

Just to help people visiting the link, the repo can be found here

Tiwiz
The Following 2 Users Say Thank You to tiwiz For This Useful Post: [ Click to Expand ]
 
wawan20
Old
#3  
wawan20's Avatar
Senior Member
Thanks Meter 38
Posts: 239
Join Date: Nov 2012
Location: Padang
cool, is this like a tinted statusbar module from Xposed framework??
 
chrisch91
Old
#4  
chrisch91's Avatar
Senior Member
Thanks Meter 21
Posts: 233
Join Date: Mar 2013
Sorry, but how to use this?!
 
dafunk2
Old
#5  
dafunk2's Avatar
Senior Member
Thanks Meter 83
Posts: 341
Join Date: Sep 2009
Location: Firenze
Wonderful!
Can please explain how to use those lines of code?
Many people who know how to compile/decompile an apk will like to try by themselves.
Thanks for this wonderful gem

 
meethere
Old
#6  
meethere's Avatar
Senior Member
Thanks Meter 103
Posts: 709
Join Date: Jan 2012
didnt get it though !!
Get exposure, submit your biz to business web directory
India's Best Online Deals
 
Jonnyredcorn
Old
#7  
Senior Member
Thanks Meter 256
Posts: 2,038
Join Date: Nov 2011
Location: Southgate
I'm kinda confused...all my apps have the black transparent status bar except for Google Now. I've never seen the issue this fix seems to address, I just always have a black status bar when in apps.
 
Takhion
Old
#8  
Takhion's Avatar
Junior Member - OP
Thanks Meter 30
Posts: 18
Join Date: May 2011
Quote:
Originally Posted by wawan20 View Post
cool, is this like a tinted statusbar module from Xposed framework??
Well the final result is similar, although you don't need the Xposed framework but just "simple" Android 4.4 and it's something to implement while developing an app, not for every installed app
The Following User Says Thank You to Takhion For This Useful Post: [ Click to Expand ]
 
hypocritelecteur
Old
#9  
Senior Member
Thanks Meter 172
Posts: 661
Join Date: Apr 2013
This is not for end users. This is for app developers folks!
The Following User Says Thank You to hypocritelecteur For This Useful Post: [ Click to Expand ]
 
LeJolly
Old
#10  
LeJolly's Avatar
Senior Member
Thanks Meter 114
Posts: 358
Join Date: May 2013

 
DONATE TO ME
Quote:
Originally Posted by Jonnyredcorn View Post
I'm kinda confused...all my apps have the black transparent status bar except for Google Now. I've never seen the issue this fix seems to address, I just always have a black status bar when in apps.
Same here, never seen that happen before!

Sent from my Nexus 5 using XDA Premium 4 mobile app
Quote:
oh god snakewood...the egg evolves twice, then you use a stone on it and you get...Legendary dogs? wot?
- BlitzkriegOmega
Quote:
I'm never going back, the past is in the paaaast!
- Me after the last day of school / Frozen Elsa
 

Tags
android, development, theme, translucent, translucent status bar
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes