Widget.* ScrollView How to Change backgroundColor

myScroller = widget.newScrollView { top = 35, left = 0, width = screenW, height = screenH - 100, scrollWidth = 600, scrollHeight = 800, listener = scrollListener, hideBackground = false, backgroundColor = { 0.4, 0.4, 0.4 } -grey } myScroller.backgroundColor = { 1.0, 0.6, 0.1 } --(yellowish) not working

Does anyone know how to set backgroundColor of the scrollView? I searched the forums everyone using images, I don’t want to use Image I just want to change background color of scrollView when button is clicked. 

Example:

If I click Red button, then myScroller.backgroundColor = { 1,0,0}

If I click Green Button then myScroller.backgroundColor = {0,1,0}

Regards

Ali

Heya the sollution is simple, place display.newRect behind scrollView and change color of it. Simplest and best soultion in my opinion :slight_smile: as you can do many things with it.

Solution is simple and it resolved the problem. But it doesn’t change the scrollView backgroundColor. I am going to keep this unSolved so that in next release of Corona, developers do add function like setBackgroundColor to scrollView.

The other solution but its not as good as first one is to redraw scrollView with changed background color, for example:

backgroundColor = colorTab -grey

if button pressed then colorTab = {1,0,0}

 then redraw scrollView by puttin in in function and calling removeSelf and then 

scrollViewDrawer()

The scrollView background is not accessible.  If you would like this feature, please go to http://feedback.coronalabs.com and request it there.  However, the widget code is available at https://github.com/coronalabs/framework-widget

This is all .lua code, it’s open source.  You can download it and make whatever modifications you need for your project.

Rob

Thanks Rob, I read the code in file widget_scrollView.la   I think it will be possible if under public methods there will be a new function like this

 -- Function to set the background pf scrollView function scrollView:setBackgroundColor( newRed, newGreen, newBlue ) -- check if any viewBackground Exist remove it self.\_view.\_background:removeSelf() -- or nil -- Create the view's background newBackground = display.newRect( scrollView, 0, 0, opt.width, opt.height ) newBackground = 0 newBackground = 0 newBackground:setFillColor(newRed,newGreen,newBlue) self.\_view.\_background = newBackground self.\_view.\_background:toBack() -- if it overlays existing content end

I can’t compile this open source  and test it, but my mind is saying if the above code runs It might put new rectangle on top of the existing scrollView content. Thant can be solve by using toBack().

The logical thing is change the background instead of being a local variable inside the create function to add it as a child object to the scrollView itself.  Then you could just do a setFillColor() on the exposed background.

Rob

Heya the sollution is simple, place display.newRect behind scrollView and change color of it. Simplest and best soultion in my opinion :slight_smile: as you can do many things with it.

Solution is simple and it resolved the problem. But it doesn’t change the scrollView backgroundColor. I am going to keep this unSolved so that in next release of Corona, developers do add function like setBackgroundColor to scrollView.

The other solution but its not as good as first one is to redraw scrollView with changed background color, for example:

backgroundColor = colorTab -grey

if button pressed then colorTab = {1,0,0}

 then redraw scrollView by puttin in in function and calling removeSelf and then 

scrollViewDrawer()

The scrollView background is not accessible.  If you would like this feature, please go to http://feedback.coronalabs.com and request it there.  However, the widget code is available at https://github.com/coronalabs/framework-widget

This is all .lua code, it’s open source.  You can download it and make whatever modifications you need for your project.

Rob

Thanks Rob, I read the code in file widget_scrollView.la   I think it will be possible if under public methods there will be a new function like this

 -- Function to set the background pf scrollView function scrollView:setBackgroundColor( newRed, newGreen, newBlue ) -- check if any viewBackground Exist remove it self.\_view.\_background:removeSelf() -- or nil -- Create the view's background newBackground = display.newRect( scrollView, 0, 0, opt.width, opt.height ) newBackground = 0 newBackground = 0 newBackground:setFillColor(newRed,newGreen,newBlue) self.\_view.\_background = newBackground self.\_view.\_background:toBack() -- if it overlays existing content end

I can’t compile this open source  and test it, but my mind is saying if the above code runs It might put new rectangle on top of the existing scrollView content. Thant can be solve by using toBack().

The logical thing is change the background instead of being a local variable inside the create function to add it as a child object to the scrollView itself.  Then you could just do a setFillColor() on the exposed background.

Rob