2015-06-25 32 views
0

在Android版Gmail應用,當一個或多個電子郵件被選中,工具欄變爲白色背景,返回按鈕,刪除按鈕,新的工具欄等對郵件的選擇,如Gmail

我如何能實現在Android中相同L·我知道如何在新活動(getSupportActionBar().setDisplayHomeAsUpEnabled(true))中添加後退按鈕,但無法找到此活動。

+0

你的意思[這](http://developer.android.com/guide/topics/ui/menus.html#context-menu) – calvinfly

+0

沒錯。謝謝。請輸入這個答案。 – jaks

回答

2

,你可以找到指導here

對於ListView控件或GridView控件,您可以搜索Enabling batch contextual actions in a ListView or GridView例如下面。

ListView listView = getListView(); 
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); 
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { 

    @Override 
    public void onItemCheckedStateChanged(ActionMode mode, int position, 
              long id, boolean checked) { 
     // Here you can do something when items are selected/de-selected, 
     // such as update the title in the CAB 
    } 

    @Override 
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 
     // Respond to clicks on the actions in the CAB 
     switch (item.getItemId()) { 
      case R.id.menu_delete: 
       deleteSelectedItems(); 
       mode.finish(); // Action picked, so close the CAB 
       return true; 
      default: 
       return false; 
     } 
    } 

    @Override 
    public boolean onCreateActionMode(ActionMode mode, Menu menu) { 
     // Inflate the menu for the CAB 
     MenuInflater inflater = mode.getMenuInflater(); 
     inflater.inflate(R.menu.context, menu); 
     return true; 
    } 

    @Override 
    public void onDestroyActionMode(ActionMode mode) { 
     // Here you can make any necessary updates to the activity when 
     // the CAB is removed. By default, selected items are deselected/unchecked. 
    } 

    @Override 
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 
     // Here you can perform updates to the CAB due to 
     // an invalidate() request 
     return false; 
    } 
});