package com.example.actionbartest;
成都創(chuàng)新互聯(lián)公司2013年成立,先為芝罘等服務建站,芝罘等地企業(yè),進行企業(yè)商務咨詢服務。為芝罘企業(yè)網站制作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欄進行監(jiān)聽
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
//截圖如下