如何在toolbar 裡加icon, 然後只彈出一個小小的menu 的 dialog

Posted in :

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, 主程式:

https://github.com/haiwen/seadroid/blob/master/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java

 

副程式:

https://github.com/haiwen/seadroid/blob/master/app/src/main/java/com/seafile/seadroid2/ui/dialog/SortFilesDialogFragment.java

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *