MainScreen Background Color
Hi,
I m trying to change the MainScreen's background color by overriding the paintBackground method... The code looks like this: protected void paintBackground(Graphics g){ System.out.println("paint background called"); super.paintBackground(g); g.setBackgroundColor(Color.BLUE); } but this code will not printing my background.....what should be the problem with this..... any help..... Thanks in advance..... |
I had tried doing the same thing .. but it did not work.
A possible turn around could be put a Field Manager on the mainscreen and then give the manager the background color. |
Background Image
Thanks....
Hi, Actually i want to place a background image on to the mainscreen. and some Fields on it....but there is no method to put image on to the MainScreen. So, i m overriding a Screen's paintBackground() but it will not working... The code look likes: protected void paintBackground(Graphics g){ System.out.println("paint Background called"); int XWidth=g.getScreenWidth(); int YHeight=g.getScreenHeight(); g.clear(); g.drawBitmap(0,0,XWidth,YHeight,bitmap,0,0); } but, the above code not working properly.... Any idea??????? |
Quote:
Hello, I have an idea :) To set background image or background color you should: 1. implement Manager class (can be VerticalFieldManager) 2. implement method paint () { g.drawBitmap (.. your backgound image or g.fillRect (...fill with your background color super.paint (); // draw form components } 3. add component not to screen but to your manager MyManager manager; manager.add ( new EditField ()); screen.add (manager); 4. override trackwhellroll and call invalidate, so you repaint your background. I know it is hard way, but it works. XXXDev |
Hi all,
Use the following code To set the background color of a screen. Code:
public void paint(Graphics graphics) { Cheers, ARIF |
Quote:
if i try this i just get a red screen... all of my buttons textfields seems to be "under" the red color |
you need to pass the graphics object to the super class, add:
super.paint(graphics); but MainScreen is build up of layout managers so you might find only part of the screen is drawn red. am looking into this at the moment, it's a mess. will report back if i succeed. |
okay - you can get the field manager from a mainscreen using:
getMainManager(); anyone know how you'd then override the paint method of this manager? |
Quote:
The problem then is that you can not set a new MainManager for the MainScreen. That's annoying. The solution I came up with was to create a derived MainScreen class that creates it's own new Manager and adds Fields to that Manager instead of the default one already created by the MainScreen. It's a bit tricky, but it works. Any fields you add are painted over the top of the background bitmap. Here's some sample code... First the new Manager class: Code:
class NewVerticalFieldManager extends VerticalFieldManager { Code:
class NewMainScreen extends MainScreen { |
Thanks for that code, bwhelan :) It works great except one small thing. For me, it's not coloring the whole screen. I'm setting a background color instead of using an image. Any ideas? I tried setting the manager to "USE_ALL_HEIGHT" but then the screen has a scrollbar, so i tried "NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL" but there's still a scrollbar there.
Code:
protected void paintBackground(Graphics graphics) |
Quote:
Hope that points you in the right direction. |
Thank you :) Doesn't getPreferredheight just return the preferred height rather than setting it? I already have the screen height saved in a variable called "screenHeight" and am now overriding the gerPreferredheight function as follows.
Code:
public int getPreferredHeight() Code:
class NewVerticalFieldManager extends VerticalFieldManager |
help..
Can someone take me by the hand.. Im not having much luck getting these code snippits working.. jfisher - I really find your www site to be helpful and you allways seem to have insiteful samples.. It would be great if there were an entire sample of how to set the background including all the imports etc. Sorry Im such a newb but I am trying ! :smile:
|
to be honest i never found a good solid way of setting the background on a MainScreen, after talking with rim i'm 90% sure they'll add it to the api in future but for now... - i did need to do this for a project recently and the method i used might seem a little messy, but the code was actually much more elegant than trying to override field managers paint methods.
what i did was to keep track of each field added to the screen and increment a counter which gave me the total height in pixels used by the fields, if this was less than the height of the screen i added a custom spacerfield (Blackberry - SpacerField) to pad the rest. the app was built up with custom fields so i had control over the colours of each and worked dynamically with both pearl and 320x240 devices. but it feels like a hack so wouldn't want to blog about it, i'm sure other more experienced proto geeks could do it better, rim certainly did in their facebook app. like everyone else, i'd love to see a nice working example including full source of setting the background colour of a MainScreen that doesn't cause more issues than it solves (it'd be a candidate for an article as this issues comes up every week it seems - i'm going to open up the dev lessons on northcubed to any other developers who want to contribute). [edit - bwhelan's example looks elegant, i'll have to try it when i get a spare minute] |
You need to set the extent in your custom manager, otherwise the default implementation will set it to the height of your one field. Add this to NewVerticalFieldManager:
Code:
protected void sublayout(int width, int height) { |
more of a sample..
like I said Im a newby .. can you post more of a sample? I have no idea how to use the sample ou just posted.
|
Here ya go, slick.
Code:
class MyAquaMarineApp extends UiApplication { |
Thanks Dick.
or do you prefer Richard? Seriously thank you very much.. Ill give it a try, but knowing my luck Im gonna hit a boatload of symbol errors.. so I will just put in the imports hopefully. Its been awhile since anyone called me slick, my best freind called me that . hah
|
The RIM KB has an entry relating to changing the background color of a screen:
How to - Change the background color of a screen And also, how you can set an image to be the background for a screen: How To - Use a background image in application screens Unfortunately, due to the poor quality of the KB search if you went there and typed in the keywords "mainscreen background color" you probably still wouldn't have been able to find the above articles (n) |
to be frank all these are working but not to thar extent .i am new to this field and i want to set the backgroungd color .i did same as u mension i.e taking the manager and override the paint and add the fields to that manager instead of that screen its working with one problem i.e. scrolling.please tell me the solution to remove that scroll bar.
LabelField labelField = new LabelField("This is a label"); AutoTextEditField deviceNumber = new AutoTextEditField ("Device No : ", "") ; backgroundBitmap = Bitmap.getBitmapResource("thanks8.png"); MainScreen mainScreen = new MainScreen(); mainScreen.setTitle("Example") ; HorizontalFieldManager defaultbgd = new HorizontalFieldManager(HorizontalFieldManager.USE_ ALL_HEIGHT | HorizontalFieldManager.USE_ALL_WIDTH){ public void paint(Graphics g) { g.setBackgroundColor(Color.LIGHTPINK); g.clear(); super.paint(g); } } ; VerticalFieldManager verticalFieldManager = new VerticalFieldManager(); verticalFieldManager.add(labelField) ; verticalFieldManager.add(deviceNumber) ; defaultbgd.add(verticalFieldManager) ; mainScreen.add(defaultbgd) ; pushScreen(mainScreen); |
All times are GMT -5. The time now is 11:11 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.