Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's some sample code. First, for a nice title bar, look here: <a href="http://www.naviina.eu/wp/blackberry/iphone-style-field-for-blackberry/" rel="nofollow noreferrer">http://www.naviina.eu/wp/blackberry/iphone-style-field-for-blackberry/</a></p> <p>To display a battery strength image:</p> <pre><code>import net.rim.device.api.system.Bitmap; import net.rim.device.api.system.DeviceInfo; ... public static Bitmap getBatteryImage(){ int batteryPercent = DeviceInfo.getBatteryLevel(); int val = 1; if(batteryPercent &gt; 80){ val = 5; }else if(batteryPercent &gt; 60 ){ val = 4; }else if(batteryPercent &gt; 40){ val = 3; }else if(batteryPercent &gt; 20){ val = 2; }else { val = 1; } Bitmap batteryImage = Bitmap.getBitmapResource("mybattery"+val+".png"); return batteryImage; } ... </code></pre> <p>You need to create images mybattery1.png to mybattery5.png, and place them in your src folder. A good size to start with is 28x11 pixels (GIMP is a good free image editor). If you used the title bar code from Naviina.eu, then insert the following code in the paint method, like so:</p> <pre><code>protected void paint(Graphics graphics) { ... int w = this.getPreferredWidth(); int h = this.getPreferredHeight(); Bitmap batteryImage = getBatteryImage(); int batteryStartY = (h - batteryImage.getHeight()) / 2; graphics.drawBitmap(w - batteryImage.getWidth(), batteryStartY, w, h, batteryImage, 0, 0); ... } </code></pre> <p>Some things to note: the image(s) do not refresh unless you invalidate the screen or push/pop to another screen. Also, you may want smaller images for a Pearl vs. a Curve or Storm. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload