在Activity中如何使用Menu
1、引用string.xml中的字符串
1) 代碼中 R.string.hello_world
2) XML中@string/hello_world
2、AndroidManifest
android:label指定Activity中標(biāo)題欄的內(nèi)容、也是應(yīng)用程序的名稱。
intent-filter中的
標(biāo)識MainActivity是應(yīng)用的主程序。
3、Toast duration
Toast.LENGTH_SHORT//2S Toast.LENGTH_LONG//3.5s
4、在Activity中使用Menu
重寫onCreateOptionsMenu()
@Override
public?boolean?onCreateOptionsMenu(Menu?menu)?{
//?Inflate?the?menu;?this?adds?items?to?the?action?bar?if?it?is?present.
getMenuInflater().inflate(R.menu.main,?menu);
return?true;//表示允許將菜單顯示出來
}重寫 onOptionsItemSelected()
@Override
public?boolean?onOptionsItemSelected(MenuItem?item)?{
//?Handle?action?bar?item?clicks?here.?The?action?bar?will
//?automatically?handle?clicks?on?the?Home/Up?button,?so?long
//?as?you?specify?a?parent?activity?in?AndroidManifest.xml.
int?id?=?item.getItemId();
switch(id){
case?R.id.add_item:
Toast.makeText(this,?"add",?Toast.LENGTH_SHORT).show();
break;
case?R.id.remove_item:
Toast.makeText(this,?"remove",?Toast.LENGTH_SHORT).show();
break;
default:
}




