我正在尝试在我的某个活动中创建一个选项菜单。当我运行应用程序时,我没有看到任何选项菜单。我试图搜索如何让它出现,但找不到任何东西。这是我的代码
package com.exaple.josh.unidrive;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* Created by Josh on 1/31/2015.
*/
public class Documents extends Activity {
EditText et;
EditText txtView;
private String data;
private String file = "mydata";
private Menu menuresource;
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menuresource, (android.view.Menu) menu);
return true;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.documents);
}
public void save(View view) {
data = et.getText().toString();
try {
FileOutputStream fOut = openFileOutput(file, MODE_PRIVATE);
fOut.write(data.getBytes());
fOut.close();
Toast.makeText(getBaseContext(), "file saved",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void open(View view) {
try {
FileInputStream fin = openFileInput(file);
int c;
String temp = "";
while ((c = fin.read()) != -1) {
temp = temp + Character.toString((char) c);
}
et.setText(temp);
Toast.makeText(getBaseContext(), "file read", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
有人可以帮忙吗?