Используя приведенный ниже код для EditText вы можете получить событие для Cut/Copy/Paste
И вы должны создать EditText как below.and вы можете скрыть экранную клавиатуру после того, как выстрелил событие ...
<com.example.textlink.EditTextMonitor
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:hint="EditText" />
Создать один файл Java в пакете ...
public class EditTextMonitor extends EditText {
private final Context mcontext; // Just the constructors to create a new
// EditText...
public EditTextMonitor(Context context) {
super(context);
this.mcontext = context;
}
public EditTextMonitor(Context context, AttributeSet attrs) {
super(context, attrs);
this.mcontext = context;
}
public EditTextMonitor(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mcontext = context;
}
@Override
public boolean onTextContextMenuItem(int id) {
// Do your thing:
boolean consumed = super.onTextContextMenuItem(id);
// React:
switch (id) {
case android.R.id.cut:
onTextCut();
break;
case android.R.id.paste:
onTextPaste();
break;
case android.R.id.copy:
onTextCopy();
}
return consumed;
}
/**
* Text was cut from this EditText.
*/
public void onTextCut() {
InputMethodManager imm = (InputMethodManager) getContext()
.getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Toast.makeText(mcontext, "Event of Cut!", Toast.LENGTH_SHORT).show();
}
/**
* Text was copied from this EditText.
*/
public void onTextCopy() {
InputMethodManager imm = (InputMethodManager) getContext()
.getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Toast.makeText(mcontext, "Event of Copy!", Toast.LENGTH_SHORT).show();
}
/**
* Text was pasted into the EditText.
*/
public void onTextPaste() {
InputMethodManager imm = (InputMethodManager) getContext()
.getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Toast.makeText(mcontext, "Event of Paste!", Toast.LENGTH_SHORT).show();
}}
используйте 'edittext.requestFocus();' в вашем java-коде. – Ironman
Я пробовал, но все еще не работал. – vijay