September 22, 2014

Getting More Elbow Room

While the T-Mobile G1′s 320×480 screen is a luxury to those who developed apps for less-spacious screens, it always seems like you could use just a bit more room. Here are two tricks for clearing off some Android-supplied UI elements, so your activities can take up more space.

First up is the activity title bar. Much like the title bar in any Windows, OS X, or (most window managers in) Linux, it shows you the name of the application you are using. Sometimes, though, that is sufficiently obvious that you would rather reclaim the space from the bar. To do that, call requestWindowFeature(Window.FEATURE_NO_TITLE); from your activity’s onCreate() callback, before you set your content view.

For example, here is a snippet from the source code to Android’s calculator app:

[sourcecode language="java"]
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
[/sourcecode]

This is also useful as a trick to do a fancier title bar than the stock Android one — just remove theirs and supply your own, completely under your control.

To gain even more room, you can go “full screen”. This eliminates the status bar at the top of the phone display, where the signal strength, battery meter, and whatnot reside. Removing this is dangerous, in that your users might get irritated if they have no way to know how much battery life remains, for example. But, in select situations, it may be worthwhile.

To go “full screen”, use the following, before you set your content view:

[sourcecode language="java"]
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
[/sourcecode]

Deals, Discounts, Freebies, and More! Click here to save today!