Menu栏操作
package com.example.actionbartest;
成都创新互联公司2013年成立,先为芝罘等服务建站,芝罘等地企业,进行企业商务咨询服务。为芝罘企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
import android.os.Bundle;
import android.app.Activity;
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) {
//添加菜单项
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
//对menu栏进行监听
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.add:
Toast.makeText(this, "add", Toast.LENGTH_SHORT).show();
break;
case R.id.delete:
Toast.makeText(this, "delete", Toast.LENGTH_SHORT).show();
break;
case R.id.save:
Toast.makeText(this, "save", Toast.LENGTH_SHORT).show();
break;
case R.id.help:
Toast.makeText(this, "help", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
//menu/menu.xml
//values/strings.xml
//截图如下
新闻标题:Menu栏操作
新闻来源:http://azwzsj.com/article/gsdsjp.html