public void closeOptionsMenu ()
Since: API Level 1 Progammatically closes the options menu. If the options menu is already closed, this method does nothing. Activity里面的这个函数,关闭的是神马menu?
Since: API Level 1 Progammatically closes the options menu. If the options menu is already closed, this method does nothing. Activity里面的这个函数,关闭的是神马menu?
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;public class HelloActivity extends Activity {
private Button button = null;
private TextView tx = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
HelloActivity.this.closeOptionsMenu();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(0, 1, 1, "about");
menu.add(0,2,2,"exit");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId() == 1){
Toast.makeText(HelloActivity.this, "about", Toast.LENGTH_SHORT).show();
}
else if(item.getItemId() == 2){
Toast.makeText(HelloActivity.this, "exit", Toast.LENGTH_SHORT).show();
}
return super.onMenuItemSelected(featureId, item);
}
}我也是这么理解的,怎么没有效果呢?
public void closeOptionsMenu() {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "closeOptionsMenu", Toast.LENGTH_SHORT)
.show();
}
这样就会有反应,希望能帮到你