邮件选择的新工具栏,如Gmail

时间:2015-06-25 01:20:17

标签: java android android-5.0-lollipop

在Android Gmail应用中,当选择一个或多个电子邮件时,工具栏将变为白色背景,并带有后退按钮,删除按钮等。

我如何在Android L中实现相同的功能?我知道如何在新活动(getSupportActionBar().setDisplayHomeAsUpEnabled(true))中添加后退按钮,但无法找到此活动。

1 个答案:

答案 0 :(得分: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;
    }
});