toolbar 裡加icon很簡單,寫在 Activity 的:
@Override 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_tab2015, menu); return true; }
menu 的判斷寫在 Activity 的:
@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();
如何彈出 menu dialog, 先寫一個 class , class 裡放一個 interface, 然後在 activity 裡去 implements 那一個 interface, 然後就可以變成在 fragment 裡去執行 activity 裡的 function.
sample, 主程式:
副程式: