Google Glass gdk-menu

Source: Internet
Author: User

Let's talk about the menu in the Development of Google Glass gdk. (The last section is really JB rotten = This section is also in my opinion in the future, so I will write a little bit about it and wait until the technology is mature, and then I will come up with a complete set of tutorials !)

Let's take a look

 

Start :)

Remove the original topic first.

Remove Android: Theme From androidmanifest. XML, and edit our menu in RES/menu/Main. xml.

The glass menu has three options (in general): ID, title, and Icon (50x50 pixels white transparent background)

So our XML Code is as follows:

1 <menu xmlns: Android = "http://schemas.android.com/apk/res/android" 2 xmlns: Tools = "http://schemas.android.com/tools" 3 tools: context = "com. google. menutest. mainactivity "> 4 5 <Item 6 Android: Id =" @ + ID/action_play "7 Android: Title =" play "8 Android: icon = "@ drawable/ic_music_play_50" 9/> 10 <item11 Android: Id = "@ + ID/action_pause" 12 Android: Title = "Suspend" 13 Android: icon = "@ drawable/ic_music_pause_50" 14/> 15 <item16 Android: Id = "@ + ID/action_quit" 17 Android: title = "exit" 18/> 19 </menu>

OK, then we will write the menu Click Event in Java:

1 @ override 2 Public Boolean onoptionsitemselected (menuitem item) {3 Switch (item. getitemid () {4 case R. id. action_quit: 5 system. out. println ("exit the program! "); 6 system. Exit (0); 7 break; 8 case R. Id. action_play: 9 system. Out. println (" start playing! "); 10 break; 11 case R. Id. action_pause: 12 system. Out. println (" pause! "); 13 default: 14 break; 15} 16 return Super. onoptionsitemselected (item); 17}

That's easy to understand, right? It is not much different from Android, but the next step is the most important event-touchpad click event.

When the touchpad is clicked, a menu is displayed. We add an onkeydown event, which requires two parameters (INT keycode and keyevent ).

1     public boolean onKeyDown(int keyCode, KeyEvent keyEvent){2         if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER){3             openOptionsMenu();4             return true;5         }6         return false;7     }

Keyevent. keycode_dpad_center is the ID of the touchpad click event. You haven't figured out what you want to do to the right, so I will talk about it later ~

It's okay. Let's start with the code.

1 @ override 2 protected void oncreate (bundle savedinstancestate) {3 super. oncreate (savedinstancestate); 4 // setcontentview (R. layout. activity_main); 5 card card1 = new card (this); 6 card1.setimagelayout (card. imagelayout. full); 7 card1.addimage (R. drawable. img2); 8 card1.settext ("caomud horse player"); 9 card1.setfootnote ("137rry"); 10 view = card1.getview (); 11 setcontentview (View); 12}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.