android键盘不显示
所以我有一个edittext,我试着让键盘在倾斜时聚焦 我正在使用摩托罗拉的一款设备MC40。Android版本2.3.4 我检查它是否对焦,我已经调试并看到它对焦了。我尝试了以下方法:android键盘不显示,android,motorola,Android,Motorola,所以我有一个edittext,我试着让键盘在倾斜时聚焦 我正在使用摩托罗拉的一款设备MC40。Android版本2.3.4 我检查它是否对焦,我已经调试并看到它对焦了。我尝试了以下方法: txtQuantity.selectAll(); txtQuantity.requestFocus(); 你,当它在我的程序的其他部分工作时,它在这个活动中不工作 edittext被聚焦,但文本未被选中,键盘不在那里。 edittext在屏幕上有点低,在其他活动中则有点高。我相信这就是键盘不显示的原因,正确还
txtQuantity.selectAll();
txtQuantity.requestFocus();
你,当它在我的程序的其他部分工作时,它在这个活动中不工作
edittext被聚焦,但文本未被选中,键盘不在那里。
edittext在屏幕上有点低,在其他活动中则有点高。我相信这就是键盘不显示的原因,正确还是错误
如果我用
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
然后显示键盘。然而,出于某种奇怪的原因,我的编辑文本框现在缩小到原来的1/3,你看不到里面写了什么
这个问题开始困扰我了
编辑:
这项活动似乎有助于解决问题。然而,我得到一个弹出窗口,要求我在3个选项中进行选择,words/all/inmethod。如果我选择中间的一个,它会工作,但我需要以编程的方式来实现
edittext.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));
编辑文本框
<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" />
您可以尝试使用:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
然后在清单文件中,您可以将以下内容放入
标记中:
android:windowSoftInputMode="adjustPan"
下面是一些对我有用的代码。我有一个类似的问题,我会专注于我的编辑文本,但键盘不会显示
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);
}
我的清单中有这个:android:windowSoftInputMode=“stateHidden | adjustResize | adjustPan”我可以问一下为什么
stateHidden
?代码库部分是继承的,不确定。我确实只换了个调音盘,但没什么不同。当使用getWindow()强制edittext get时,它被切成两半。setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u STATE\u VISIBLE);删除stateHidden
并保留另外两个怎么样?我不熟悉该方法,但不幸的是,您正在使用该方法作为解决方法。这是一个很长的目标,但可能需要检查布局中的edittext xml中是否设置了安卓:focusable=“true”?尝试发布布局xml。它最终可能会有所帮助。