# Android menu(button) related

**URL:** <https://discourse.processing.org/t/android-menu-button-related/14198>\
**Category:** Processing for Android\
**Created:** [September 25, 2019, 8:00am UTC](https://discourse.processing.org/t/android-menu-button-related/14198 "2019-09-25T08:00:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 25, 2019, 8:00am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/1 "2019-09-25T08:00:30Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4a194a2516b8f1b69fcd2143c13175fc55318cd5.jpeg)

Good morning. nice to meet you.

Like the picture above, the menu bar is basically used in Android.

Is there any layout source code like above in processing?

Or is there source code to make it like this?

Help me please.

---

<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 16, 2019, 3:13pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/2 "2019-10-16T15:13:36Z")

</div>

@GWAK  
See my code below this one.  
It works on KitKat.  
Please try on other modes.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [October 17, 2019, 5:57am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/3 "2019-10-17T05:57:45Z")

</div>

@noel

Thank you for the answer.  
Where can I find your code?  
please answer about my question.

---

<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 17, 2019, 9:15am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/4 "2019-10-17T09:15:32Z")

</div>

@GWAK See [here](https://discourse.processing.org/t/android-options-menu/14724/2).

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [October 23, 2019, 11:48am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/5 "2019-10-23T11:48:17Z")

</div>

@noel

The error occurred like this.

 ![tt](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/70ae7dea1e836a8bcb5604c2b073b59bb8248b74.jpeg)

---

<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 23, 2019, 12:02pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/6 "2019-10-23T12:02:18Z")

</div>

Strange!!

> import processing.android.CompatUtils;

It’s a processing lib widely used. A lot of android sketches will not work if this import cannot be resolved.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [October 23, 2019, 12:13pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/7 "2019-10-23T12:13:09Z")

</div>

@noel

What is your Android version?

---

<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 23, 2019, 12:31pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/8 "2019-10-23T12:31:19Z")

</div>

@GWAK  
Lollipop But this should work on above also.  
Please try changing the line:

> menubarId=CompatUtils.getUniqueViewId();

and:

> menuanchorId=CompatUtils.getUniqueViewId();

to:

> menubarId = View.generateViewId();

and:

> menuanchorId = View.generateViewId();

And ofcourse not import the CompatUtils lib.

---

<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 23, 2019, 2:14pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/9 "2019-10-23T14:14:21Z")

</div>

@ noel, @GWAK === i have tested the code from @Noel on 3 phones with lolipop, kitkat && mm and it works; i have also posted another way to make a menu, using toolbar and CompatsUtils: everything runs fine; what is more strange is that your error is not about CompatsUtils but about the processing.android!!! - Now, in some cases i have got this weird error but at the very very beginning of compiling and without consequence: if you are using exactly the code @noel that means that there is something wrong in your install or in P5 itself…

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [October 23, 2019, 12:20pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/10 "2019-10-23T12:20:53Z")

</div>

![error](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f4f2a7e0f56ee98ebaea5010e480fb389b33dbb0.jpeg)

Please see the picture above. This error occurs.  
Is there a workaround?

Help me.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [November 4, 2019, 10:29am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/12 "2019-11-04T10:29:45Z")

</div>

@noel  
@akenaton

I made this.

[![](https://img.youtube.com/vi/OmXcfHLQzB0/maxresdefault.jpg "어플리케이션 초안 사물인터넷 IoT기반 시스템구축") ](https://www.youtube.com/watch?v=OmXcfHLQzB0)

---

<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:** [November 4, 2019, 4:09pm UTC](https://discourse.processing.org/t/android-menu-button-related/14198/13 "2019-11-04T16:09:23Z")

</div>

Very Nice!! A sliding menu. Are you willing to share the code? 😂  
By the way does that mean that, as you promised in another topic to try the popup menu, it didn’t work on your phone even with the changes I suggested above?

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [November 5, 2019, 12:29am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/14 "2019-11-05T00:29:29Z")

</div>

@noel

Unfortunately, the menu bar is implemented through a picture image.  
The original purpose popup will proceed. I’ll just do it after finishing another project.

Thank you.

> boolean MENU\_BAR = false;  
> int MENU\_BAR\_TIMER = 0; int MENU\_BAR\_WIDTH = 0;  
> boolean MENU\_BAR\_GRAPHIC = false;  
> void mousePressed(){
> 
> //----------------------------------------------------------------------------//  
> // [메뉴바]  
> if(display\_n != 0){  
> x = int(0.07_width); y = int(0.05_height); w = int(0.11_width); h = int(0.06_height);  
> if ( mouse\_setting(x,y,w,h) == true){  
> if(MENU\_BAR == false) { println(“MENUBAR EVNET”); MENU\_BAR = true; MENU\_BAR\_GRAPHIC = true; MENU\_BAR\_TIMER = millis() + 800; }  
> }  
> }  
> //----------------------------------------------------------------------------//
> 
> }
> 
> void DRAW\_MENU\_BAR(){
> 
> //---------------------------------------------------------------------//  
> if(MENU\_BAR\_GRAPHIC){  
> float Speed\_value = 30.0;  
> MENU\_BAR\_WIDTH = int((float) (MENU\_BAR\_TIMER-millis()) / Speed\_value);  
> // println(MENU\_BAR\_WIDTH);  
> if( MENU\_BAR\_WIDTH \> 0 ) {  
> }else{  
> MENU\_BAR\_GRAPHIC = false;  
> MENU\_BAR\_WIDTH = 0;  
> }  
> }  
> //---------------------------------------------------------------------//
> 
> //---------------------------------------------------------------------//  
> if(MENU\_BAR) {  
> image(background3,int(((40-MENU\_BAR\_WIDTH)/40.0)_0.3_width),int(0.5_height),int(0.6_width),int(1\*height));
> 
> ```
> textSize( int(0.06*width) ); x = int(0.11*width); y = int(0.101*height); textAlign(LEFT);      
> fill(0); if(MENU_BAR_GRAPHIC == false) { text(ID,x,y); }
>      
>    
> // rectMode(CENTER); fill(255,100,100,100);  
>   
> x = int(0.56*width); y = int(0.026*height); w = int(0.08*width); h = int(0.06*height); 
> // rect(x, y, w, h); 
> if (mousePressed == true) { if( mouse_setting(x,y,w,h )) { // -> 취소
> MENU_BAR = false; MENU_BAR_GRAPHIC = false;        
> }}         
>    
> x = int(0.225*width); y = int(0.190*height); w = int(0.35*width); h = int(0.05*height); h2 = int(0.068*height); 
> // rect(x, y, w, h); rect(x, y+h2*1, w, h); rect(x, y+h2*2, w, h); rect(x, y+h2*3, w, h);     
> if (mousePressed == true) { if( mouse_setting(x,y,w,h )) { // -> VALUE VIEW
> MENU_BAR = false; MENU_BAR_GRAPHIC = false;    
> println(" DISPLAY-1");
> display_n = 1;FADE_ACTION();    
> }}
> if (mousePressed == true) { if( mouse_setting(x,y+h2*1,w,h )) { // -> VALUE VIEW
> MENU_BAR = false; MENU_BAR_GRAPHIC = false;    
> println(" DISPLAY-2"); 
> display_n = 2;FADE_ACTION();    
> }}  
> if (mousePressed == true) { if( mouse_setting(x,y+h2*2,w,h )) { // -> VALUE VIEW
> MENU_BAR = false; MENU_BAR_GRAPHIC = false;    
> println(" DISPLAY-3"); DRAW3_NUMBER = 99;
> display_n = 3;FADE_ACTION();    
> }}
> if (mousePressed == true) { if( mouse_setting(x,y+h2*3,w,h )) { // -> VALUE VIEW
> MENU_BAR = false; MENU_BAR_GRAPHIC = false;    
> println(" EXIT");
> exit();
> }}
> 
> ```
> 
> }  
> //---------------------------------------------------------------------//
> 
> }

![t1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/49a29f15318a89f36b429265c507bb0e9343692b.jpeg)

---

<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:** [November 5, 2019, 6:58am UTC](https://discourse.processing.org/t/android-menu-button-related/14198/15 "2019-11-05T06:58:26Z")

</div>

Thank you. I took a closer look. Now I understand, you did it in pure P5 code. I did something simular before, for a Menu popup. Sliding and fading with a whole screen image I took before and then switching alternately with a custom menu in the draw () function.  
It has a nice professionally look. Great!
