首页 文章

android键盘没有出现

提问于
浏览
0

所以我有一个edittext,如果它在倾斜时处于焦点状态,我会尝试使用键盘 .

我正在使用来自motorola,MC40的设备 . Android版本2.3.4 .

我检查它是否是焦点,我已经调试并看到它是焦点 . 我尝试过以下方法:

txtQuantity.selectAll();
txtQuantity.requestFocus();

当你在我的程序的其他部分工作时,它在这个活动中不起作用 .

edittext是专注于,但文本未被选中,键盘不在那里 . 编辑文本在屏幕上略微下降,在其他活动上稍微高一点 . 我相信这就是为什么键盘不显示,更正或错?

如果我强行键盘

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

然后是它显示的键盘 . 然而,由于一些奇怪的原因,我的edittext框现在缩小到原来的大小的1 / 3d,你无法看到它写的内容!

这个问题开始转向我了 .

Edit

这个事件似乎有所帮助,作为一种解决方法 . 但是,我得到一个弹出窗口,要求我在3个选择,单词/所有/ inmethod之间进行选择 . 如果我选择中间的,它可以工作,但我需要以编程方式做一些如何 .

edittext.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));

The edittextbox

<EditText
    android:id="@+id/..."
    android:layout_width="60dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/..."
    android:layout_alignRight="@+id/..."
    android:layout_below="@+id/..."
    android:layout_marginTop="10dp"
    android:layout_toRightOf="@+id/..."
    android:ems="10"
    android:hint="@string/..."
    android:imeOptions="actionDone"
    android:inputType="number"
    android:maxLength="10"
    android:nextFocusUp="@+id/..."
    android:selectAllOnFocus="true" />

2 回答

  • 0

    您可以尝试使用:

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    

    然后在您的清单文件中,您可以将以下内容放在 <activity> 标记中:

    android:windowSoftInputMode="adjustPan"
    
  • 0

    这是一些适合我的代码 . 我有一个类似的问题,我会在我的EditText上请求聚焦,但键盘不会显示 .

    public static void showKeyboardForEditText(Context context, EditText editText) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    }
    

    如果您需要关闭键盘,请输入以下代码:

    public static void hideKeyboard(Context context, EditText editText) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    }
    

相关问题