代码如下
package com.example.administrator.logintest;
import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class login extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_login);
Button button1=(Button) findViewById(R.id.button);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Toast.makeText(login.this,”You clicked Button”,Toast.LENGTH_SHORT).show();
}
});
}
public boolean onCreatOptionMenu(Menu menu){
getMenuInflater().inflate(R.menu.amenu,menu);
Toast.makeText(this,”You clicked”,Toast.LENGTH_SHORT).show();
return true;
}
public boolean onOptionItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.add_item:
Toast.makeText(this,”You clicked Add”,Toast.LENGTH_SHORT);
break;
case R.id.remove_item:
Toast.makeText(this,”You clicked Remove”,Toast.LENGTH_SHORT);
break;
default:
}
return true;
}
}
解决方案
50
二楼正解,你方法名不对 public boolean onCreatOptionsMenu
CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明android 按menu键菜单不会弹出来 没反应!