package com.example.menu2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.create:
Toast.makeText(MainActivity.this, "创立文件", Toast.LENGTH_SHORT).show();
break;
case R.id.open:
Intent intent = new Intent(MainActivity.this, NextActivity.class);
item.setIntent(intent);
// Toast.makeText(MainActivity.this, "打开文件", Toast.LENGTH_SHORT).show();
break;
case R.id.load:
Toast.makeText(MainActivity.this, "加载", Toast.LENGTH_SHORT).show();
break;
case R.id.save:
Toast.makeText(MainActivity.this, "保留", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
package com.example.menu2;
import android.app.Act