# Change the PRESENT mode background color in android

**URL:** <https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006>\
**Category:** Processing for Android\
**Created:** [September 16, 2019, 2:22am UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006 "2019-09-16T02:22:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [September 16, 2019, 2:22am UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/1 "2019-09-16T02:22:39Z")

</div>

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

```auto
void setup(){
size(200,200);
frame.setBackground(new java.awt.Color( 255 , 0 , 0 ));
}

```

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

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [September 16, 2019, 9:30am UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/2 "2019-09-16T09:30:16Z")

</div>

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

```auto
root.setBackgroundColor(Color.parseColor("#ffffff"));

```

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

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [September 16, 2019, 4:52pm UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/3 "2019-09-16T16:52:36Z")

</div>

@akenaton  
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(android.R.id.content);  
> return (FrameLayout) \_root.getChildAt(0);  
> }

By I still don’t have a working code.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [September 16, 2019, 5:07pm UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/4 "2019-09-16T17:07:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [October 6, 2019, 12:26pm UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/5 "2019-10-06T12:26:13Z")

</div>

Hi @akenaton  
When I use in my setup()

```auto
act = this.getActivity();
root = act.getWindow().getDecorView().findViewById(android.R.id.content);
println(root);
// root.setBackgroundColor(Color.BLUE); 

```

I get in my console:

```auto
android.support.v7.widget.ContentFrameLayout{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?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [October 7, 2019, 5:32pm UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/6 "2019-10-07T17:32:14Z")

</div>

@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…

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [October 7, 2019, 8:50pm UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/7 "2019-10-07T20:50:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [October 8, 2019, 9:42am UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/8 "2019-10-08T09:42:46Z")

</div>

@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…

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [October 8, 2019, 11:52pm UTC](https://discourse.processing.org/t/change-the-present-mode-background-color-in-android/14006/9 "2019-10-08T23:52:48Z")

</div>

@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.
