EDITTEXT,使上长按选择,但不显示上下文菜单? [英] Edittext that make selection on long click but do not show context menu?

查看:910
本文介绍了EDITTEXT,使上长按选择,但不显示上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提供自定义的切割处理,复制文本。

i want to provide custom handlers that cut,copy text.

在Longclick目标

Target on Longclick


  1. 不应该出现的右键菜单。

  2. 文字可以得到与追踪(或拖动器)中选择。

在这里输入的形象描述

[更新]

 protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    edittext = (EditText) findViewById(R.id.notetext);
    . . . .

    edittext.setCustomSelectionActionModeCallback(new ActionMode.Callback()
    {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu)
        {
            return true;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

  . . . .

}

@Override
public void onSupportActionModeStarted(android.support.v7.view.ActionMode mode) {
    super.onSupportActionModeStarted(mode);
    View v = new View(MainActivity.this);
    mode.setCustomView(v);
    mode.getMenu().clear();
    mode.getMenu().close();
    mode.finish();
}

使用上面一块code,我能够去除全部选中,剪切,复制和再贴仍然显示文本选择

Using above piece of code i am able to remove Select All, Cut, Copy and Paste.But Still it shows "Text Selection"

下面图像显示需要什么。

Below Image shows what is required.

推荐答案

要摆脱ActionMode的?并创建自己的?

you want to get rid of the ActionMode? and create your own??

您可以覆盖这一点,并得到通知时,默认为将要显示

you can override this and get notified when the default is about to be displayed

  @Override
  public void onSupportActionModeStarted(ActionMode mode) {     
    super.onSupportActionModeStarted(mode);
    //you can add your custom ui here
    mode.setCustomView(....);// it takes a view
}

如果你想关闭它,那么你叫 mode.finish(); 可以称之为有关闭或是否完成,如果你不需要它

if you want to close it then you call mode.finish(); you can call it there to close if or finish it if you do not need it.

当它即将死去调用此onSupportActionModeFinished(ActionMode模式)`我已经指出的方法是对支持库,希望你知道的。

when it is about to die it calls this onSupportActionModeFinished(ActionMode mode)` the methods i have stated are for the support libraries, hope you know that.

剩下的就是奶酪

这篇关于EDITTEXT,使上长按选择,但不显示上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆