Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Alternatives to MainScreen.setBackground() (which doesn't work)

Hi.

 

I cannot set the background of one of my Screens (which extends mainScreen). It's white no matter what I try.

 

Now I've read an article in the knowledgebase (mainScreen explained) which shows a workaround and mentions that setBackground never works for MainScreens.

 

But the reason I'm extending MainScreen is because I absolutely need the setTitle() and setStatus() methods. So I need the functionality of the MainScreen and I need a background. One that doesn't scroll and is always behind every field I add.

 

Any suggestions??

 

Thanks.

Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

I tried the following and it works slightly:

 

getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(Color.

WHITE, Color.WHITE, Color.BLUE, Color.BLUE));

 

Problem is it scrolls with my fields. I would like the color to stay where it is not stretch to take up the field container area.

 

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

1. Create your MainScreen with explicit NO_VERTICAL_SCROLL.

2. Add a VerticalFieldManager with VERTICAL_SCROLL | VERTICAL_SCROLLBAR to the screen.

3. Add the rest of the fields to this scrolling manager.

4. Set background on the main manager just as you've done.

 

This has a good chance to work properly. If it doesn't, override your scrolling manager's paintBackground and use drawShadedFilledPath. Don't forget to add getHorizontalScroll to all xPts and getVerticalScroll to all yPts in order for the background to stay docked. The first part is not that relevant for a manager without horizontal scroll, but it's a good discipline anyway. You can omit it as long as you understand what you are doing.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

Thanks for the reply.

 

Makes sense, but this way I'll lose the setTitle() and setStatus() functionality. I need these for my header image and toolbar to work properly.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

You absolutely retain your banner, status and title functionality - what made you think you would lose them?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

Sorry I think I misunderstood.

 

I was just thinking that VerticalFieldManager doesn't have setTitle() and setStatus() methods, but I'm sure you were thinking I should just call these methods for the mainScreen.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

Exactly. When you setBanner, setTitle and setStatus on the MainScreen, it subsequently limits the width and height passed into the sublayout of its main manager. If that main manager is not scrolling, it then passes the same values to your VerticalFieldManager's sublayout (scrolling managers let their children have (Integer.MAX_VALUE >> 1) total size along the scrolling axis).

 

So the conclusion is this: your title and status will be intact; your inner manager will have properly reduced visible height because of them.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

What if I need it to scroll?? In my case I have lists.

 

Would I have to place a scrollable VerticalFieldManager inside the NonScrollable one??

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Alternatives to MainScreen.setBackground() (which doesn't work)

That's exactly what I said when I outlined what you need to do. :smileyhappy:

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!