Change the PRESENT mode background color in android

In normal java mode we can change the frame bacground color with f.i.:

void setup(){
frame.setBackground(new java.awt.Color( 255 , 0 , 0 ));

But android does not work with the awt lib, but seemingly the lib instead
How can we change the layout color in android mode.

@noel ===
you have to get the root view


(you can also use the predefinite colors from android: Color…GREEN, RED, WHITE…)

Thanks. I just program for my electronic projects, and learn some java android on the fly, but having a hard time.
Until now I found

public FrameLayout getRootFramelayout() {
if (_root == null) _root = (FrameLayout) getActivity().getWindow().getDecorView().findViewById(;
return (FrameLayout) _root.getChildAt(0);

By I still don’t have a working code.

@noel ===
i am working now
i send you the code tomorrow
your code is quite good but not completely…

Hi @akenaton
When I use in my setup()

act = this.getActivity();
root = act.getWindow().getDecorView().findViewById(;
//  root.setBackgroundColor(Color.BLUE); 

I get in my console:{41d76750 V.ED.... ......ID 0,0-800,1255 #1020002 android:id/content}

which really is the size of my tablet screen, but when I try to set the background color, the sketch crashes. Any hint?

@noel === the app crashes because you have not created a runnable to change the UI; doing that it does not crash; yet, bad news: even if you change the background color it remains some kind of white (250,250,250); i have tried to understand why and now i think that the theme fixed by the main activity is the cause of that, knowing that in a fragment you cannot change the theme: it s fixed by the mainActivity and if you export your app as android you can see that the theme is hard coded in the values.xml…There can be a workaround that i have tried partially tried (and it seems to work though it is stupid) : you create a layout and set ils background to some color, you add this layout and you get the window colored as you want. Problem is that doing so you cannot see the layout created before; some solution i have to explore could be to remove all views before creating the layout, then add the layout then add all views in order to modify the hierarchy… i ll try and tell you - Yet i begin to think that all this stuff could be done in 5 minuts with AS : you create another theme in the xml values, give it some background color and change the used theme in the Manifest and in the mainActivity…

Thank you very much for taking the time to look in to this @akenaton
The reason for wanting to use this, is because in my sketches I use a lot of numbered rulers with pointers.
Because of the large variety of screen sizes I have to ‘pgraphic’ design them because using images and resize to amplify them will blur the lines.
My idea is to get the size of the screen and then let the app choose one of the (in the program prepared) most common screen sizes. The region outside the size() I would then give the same color of the app, for use with slightly different screen sizes.
With my simple understanding of android I expected that the sketch when “sized” would be a fragment, and not the underlying layout of the main activity. I really do not understand this. The workarround I am implementing now is to avoid the width and height parameters, and get the phone’s screen size, and then translate() the coordinate system in a way that the fixed prepared screen size will be centered.
Once again thanks. If you have the time I would appreciate very much a small explication of the use of fragment in Processing.

@noel === ok; now i understand your problem & think that your workaround is a good idea, though it does not solve the general problem ( as soon as i get some time left i ll try again, using the way i have explained) - As for understanding what P5 is doing you have to export for android and look to the created files: there is a a mainActivity which is doing the job and you can see that the frameLayout created on the fly has not any background color, the color will be declared when you use background() in your sketch, so when you change the default size (FullScreen) to some size<to it you can see no color except inside your sketch, no color means: the color declared by the Apptheme in the Manifest and applied to the decorView - At this point with AS you can see the styles declared inside the .xml and you can modify it (adding a custom style) but with P5 you cannot see this file and of course change it! - If your sketch was an activity you could use setBackground() for th rootview but that is not possible for a fragment…

@akenaton Great. I will wait, and also try your suggestion and install AS as soon as I get my PC fixed. Until then I am stuck with my tablet.