我希望我登入的時候,APP上的橫幅會show我的名字,該如何做?
這是一個登入畫面,我希望登入後右上角會變成我的名字
首先,先宣告
private Menu menu;
然後到onCreateOptionsMenu加入這些,(要切換的條件自己設定)
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
if(account==null){
menu.findItem(R.id.login).setTitle("登入");
}
else{
menu.findItem(R.id.login).setTitle("歡迎"+name);
}
this.menu = menu;
return true;
}
這樣就可以切換囉!!
文章標籤
全站熱搜