2015年10月16日 星期五

Android toolbar / actionbar find id and use

Android toolbar / actionbar find id and use

Android 的 Menu item 得在 onCreateOptionMenu 裡面 find


如圖指定到 Munu , find 完就可以使用
假設我想讓 photobtn 隱藏
直接使用 photobtn.setVisible(false);

如果要做按鈕點選事件, 到 onOptionsItemSelected


如圖範例, 我 switch 去抓 (MenuItem 裡面的 Item id) 去動作如 : 叫他吐個 Toast say hello

switch (item.getItemid())
{
           case R.id."你id名稱":
                                 action;
                          break;
}

Menu note 就到這了

沒有留言:

張貼留言