1
按照StopWatch GDK示例中的指導原則和約定,我無法打開MenuOption。爲Google Glass創建選項菜單
我的應用程序編譯,並能輸出「@@@@ TEST」的」嵌入式日誌語句,但似乎沒有OptionsMenu。
https://developers.google.com/glass/develop/gdk/ui/immersion-menus
這是菜單的Android的API中的方法。
openOptionsMenu();
我立足的代碼關閉秒錶的慣例:
/*
*
* Menu Code
*/
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
@Override
public boolean onKeyDown(int keycode, KeyEvent event) {
if (keycode == KeyEvent.KEYCODE_DPAD_CENTER) {
openOptionsMenu();
Log.v("@@@@","TEST");
return true;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Implement if needed
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection. Menu items typically start another
// activity, start a service, or broadcast another intent.
switch (item.getItemId()) {
case R.id.stop:
//startActivity(new Intent(this, StopStopWatchActivity.class));
Log.v("@@@@","HI");
return true;
case R.id.read_aloud:
Log.v("@@@@","READ_ALOUD");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//open the optionsMenu to make sure
@Override
public void openOptionsMenu() {
super.openOptionsMenu();
}
用於菜單的XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/read_aloud"
android:title="@string/read_aloud"
android:icon="@drawable/ic_launcher"/>
<item
android:id="@+id/stop"
android:title="@string/stop"
android:icon="@drawable/ic_launcher"/>
</menu>