@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); Button menuButton = (Button) findViewById(R.id.menuButton);
menuButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openOptionsMenu();
}
});
} /**
* {@inheritDoc}
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); menu.add("Painting");
menu.add("Photos");
menu.add("Science"); // Return true so that the menu gets displayed.
return true;
} /**
* {@inheritDoc}
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
Timer timing = new Timer();
timing.schedule(new TimerTask() { /**
* {@inheritDoc}
*/
@Override
public void run() {
closeOptionsMenu();
}
}, 10000);
return super.onPrepareOptionsMenu(menu);
}
标签:控件,菜单,menuButton,menu,程序,add,Override,public,inheritDoc
From: https://blog.51cto.com/u_16166892/6523959