Android Long Press on Edit Text behavior

前端 未结 3 662
攒了一身酷
攒了一身酷 2020-12-05 21:44

Is it possible to add something to the list of items that shows up when a user long presses on any Edit Text? (Cut, copy paste, select text, select all, input method) I want

3条回答
  •  情话喂你
    2020-12-05 22:11

    There are 2 ways: 1st one described by Shahab. 2nd one is more simple. You need to just override standard method of your activity, like:

    @Override
    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo)
    {
           if(view.getId()==R.id.MyEditTextId)
           {
                menu.add(Menu.NONE, MyMenu, Menu.NONE, R.string.MyMenuText);
           }
           else
              super.onCreateContextMenu(menu, view, menuInfo);
    }
    

    After that you'll have on long press popup context menu

提交回复
热议问题