Android ActionMode mode use

ActionMode mode

ActionMode mode is to generate a suspended ActionBar-like control on the page, suspended above the ActionBar.
The advantage of using it is that there is no need to add operation controls on the page, making full use of the page space.

ActionMode startup method

This method is implemented in the Activity class and can be used by inheriting from the Activity class.

// API11加入(默认模式TYPE_PRIMARY)
public ActionMode startActionMode(ActionMode.Callback callback);
// API23加入
public ActionMode startActionMode(ActionMode.Callback callback, int type);

TYPE_PRIMARYAPI23 adds the type structure with type, respectively TYPE_FLOATING
TYPE_PRIMARY: The action mode is treated as a Primary mode. This is the default. (default type)
TYPE_FLOATING: The action mode is treated as a Floating Toolbar. (Floating toolbar type, callback needs to be used ActionMode.Callback2, implementation onGetContentRectmethod, positioning the floating toolbar position)

ActionMode listener callback

Implement the ActionMode.Callback interface.

private class MyActionModeCallback implements ActionMode.Callback {

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // ActionMode创建,定义menu菜单。
            MenuInflater menuInflater = mode.getMenuInflater();
            menuInflater.inflate(R.menu.action_mode_menu, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            // ActionMode工作前的预先处理
            mode.setTitle("ActionMode");
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // menu菜单Item点击回调
            if (item.getItemId() == R.id.menu_confirm) {
                mode.finish();
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            // ActionMode模式结束处理(点击左侧取消,或者点击返回键结束ActionMode模式)。
            // ActionMode.finish()执行后会结束ActionMode模式,此时会执行这里。
        }
    }

ActionMode style customization

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- 左侧返回按钮图片 -->
    <item name="actionModeCloseDrawable">@mipmap/ic_launcher</item>
    <!-- 其他需要修改样式可以在这里自定义 -->
</style>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324475716&siteId=291194637