We’re almost there. All that’s left is to change the color of the background behind the logo image and make a couple of minor tweaks to alignment. I’ve left this section until almost the end of this chapter, because there’s not a lot new here; we’re just applying concepts that you already know.
Adding a Header Background
We want to put a black background behind the header image and align the image to the left. The second change is easy; simply change the style Field.FIELD_HCENTER toField.FIELD_LEFT (or leave it out entirely, as FIELD_LEFT is the default).
To make the image sit on a different color background, we’ll put the BitmapField inside another manager and let that manager draw the background color. We’ll use a HorizontalFieldManager. This first part should be familiar to you by now. Change the following lines in the UiFunMainScreen constructor:
The background is still white,but we’ve set the stage to change it. Now, there are two ways we can go about providing a black background. Before version 4.6 of the operating system,we would have to subclass the HorizontalFieldManager and modify the paint method. In version 4.6, RIM introduced a new method. We’ll cover both methods briefly.
There’s a simple Java construct called an anonymous inner class that lets us define a class at the same time as we instantiate it, if we need only one instance of the new class, as we do here. I’ll present the code and discuss it afterward. Replace the new HorizontalFieldManager line with the following lines:
This code redefines the paint method only for this instance of HorizontalFieldManager. The new paint method is simple. It just clears the entire background of the manager to black and then calls super.paint to draw the rest of the manager as before.
Using Background and BackgroundFactory
The version 4.6 of the JDE and operating system introduced borders and backgrounds, which can be used to modify the appearance of UI components. For this to work, you have to use JDE 4.6 or later, or configure the Eclipse Plug-in to use the JDE component pack 4.6 or later. The border and background classes can be found in the net.rim.device.api.ui.decor package. We’re interested in BackgroundFactory and Background. The code is pretty self-explanatory—we create a solid black background, and attach it to our HorizontalFieldManager:
Both the subclass method and the background method produce the same result.
A black background for our image
Which method should you use to set the background color? For now, I recommend subclassing Horizontal Field Manager, because it works with versions of the operating system before 4.5, and a lot of devices out there are still running those operating systems. If you use BackgroundFactory and Background, your application will not run on devices with version 4.5 or older. In the future though, expect this to change. Think of this as a sneak preview of the way BlackBerry development will be done in the near future.
Making Minor Tweaks
Just to complete the look we wanted, we’ll do a couple of small things. First, we want the labels to be indented from the left side a bit—we’ll accomplish that just by adding a few spaces to the beginning of the Username label—since everything is in a grid layout, the other fields will still line up with the right side of the label:LabelField usernameLabel = new LabelField(" Username:", Field.FIELD_RIGHT); Finally, let’s align the Remember password check box to the right. Just add the Field.FIELD_RIGHT alignment style to it:
Now,our main screen is exactly as we wanted to see it, as illustrated in Figure.
The finished UiFun main screen
BLACKBERRY Related Interview Questions
|J2ME Interview Questions||BLACKBERRY Interview Questions|
|Android Interview Questions||Retail Interview Questions|
|Telecommunication Project Management Interview Questions||Mobile Testing Interview Questions|
|Telemarketing Interview Questions||Mobile Application Testing Interview Questions|
|Mobile Marketing Interview Questions||Telecom Billing Interview Questions|
|Mobile Application Architect Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.