在Android中设置textIsSelectable(true)后,软键盘无法打开

为了在不显示软键盘的情况下选择edittext,我放了edittext.textIsSelectable(true)属性,我隐藏了软键盘.

当我再次尝试打开软键盘时,它没有打开.

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

谢谢

解决方法:

通过使用EditText的以下代码,您可以获得剪切/复制/粘贴的事件
你必须创建如下所示的editText.你可以在事件发生后隐藏软键盘……

<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();
}}
上一篇:如何在Android中隐藏无键盘的软键盘?


下一篇:macos – 用于编程的最方便的键盘/键盘布局是什么?