在Android中设置textIsSelectable(true)后软键盘未打开

在Android中设置textIsSelectable(true)后软键盘未打开,android,keyboard,android-edittext,android-softkeyboard,Android,Keyboard,Android Edittext,Android Softkeyboard,要使edittext在不显示软键盘的情况下可选择,我已设置了edittext.textIsSelectable(true)属性,并隐藏了软键盘 当我再次尝试打开软键盘时,它无法打开 我尝试在edittext中设置setFocusable(true),但键盘仍然没有打开。 如有任何建议,将不胜感激 谢谢您没有设置属性edittext.textselectable(true) 您可以选择输入的文本并将其正确复制,为什么不盲目使用具有基本属性的edittext通过使用下面的edittext代码,您可以

要使edittext在不显示软键盘的情况下可选择,我已设置了
edittext.textIsSelectable(true)
属性,并隐藏了软键盘

当我再次尝试打开软键盘时,它无法打开

我尝试在edittext中设置
setFocusable(true)
,但键盘仍然没有打开。 如有任何建议,将不胜感激


谢谢您

没有设置属性
edittext.textselectable(true)


您可以选择输入的文本并将其正确复制,为什么不盲目使用具有基本属性的edittext

通过使用下面的edittext代码,您可以获得剪切/复制/粘贴事件 你必须像下面那样创建编辑文本。你可以在事件触发后隐藏软键盘

<com.example.textlink.EditTextMonitor
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:hint="EditText" />
我找到了答案

只需重写Edittext中的
isTextSelectable()
方法

如果要打开键盘,请返回
super.istextselective()

如果不想打开键盘,则返回
true


就这样。它对我很有用。

使用
edittext.requestFocus()在java代码中。我尝试过,但仍然不工作。我不希望在edittext中选择某些文本时键盘处于打开状态,这就是原因。我认为这是在不影响选择的情况下隐藏键盘的唯一方法。如果您知道在选择文本时隐藏键盘的其他方法,欢迎您回答::-)我删除了文本选择,现在它正在工作。此外,没有此属性,文本也可以选择。你好,Santhosh,谢谢你的回复。我真的很感激。但问题是当我们在edittext中选择一些文本时,软键盘不应该打开。在您选择剪切、复制或粘贴后,我们只能隐藏软键盘。但在我看来,在选择剪切、复制或粘贴之前,键盘应该是隐藏的。谢谢。将此属性设置为false,甚至将其从XML中删除也是一样的。
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();
}}