我有一个编辑文本作为我的结果的输出和它的可编辑文本,因此用户通过长按可以剪切,复制和粘贴文本..所以我需要编写我的应用程序以显示操作栏长按,这样用户只能复制文字!! 我在问题中看到了这段代码,但代码中遗漏了一些函数:
VancoSR.setCustomSelectionActionModeCallback(new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View p1)
{
// TODO: Implement this method
startActionMode(new ActionBarCallBack());
return false;
}
});
}
class ActionBarCallBack implements ActionMode.Callback
{
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item)
{
// TODO Auto-generated method stub
switch(item.getItemId()) {
case R.id.copyText:
Toast.makeText(getApplicationContext(), "Copy", Toast.LENGTH_SHORT).show();
return true;
case R.id.pasteText:
Toast.makeText(getApplicationContext(), "Paste", Toast.LENGTH_SHORT).show();
return true;
case R.id.cutText:
Toast.makeText(getApplicationContext(), "Cut", Toast.LENGTH_SHORT).show();
return true;
case R.id.help:
Toast.makeText(getApplicationContext(), "Help", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu)
{
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(R.menu.contextual_menu, menu);
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode)
{
// TODO Auto-generated method stub
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu)
{
// TODO Auto-generated method stub
return false;
}