我正在Activity
.I中创建一个Fragment
,在MainActivity
布局中有一个EditText
,而当我单击EditText
时软键盘不显示时,软键盘布局就会出现问题。
在我创建的EditText
布局中
<EditText
android:id="@+id/edt_searchContact"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textCursorDrawable="@drawable/color_cursor"
android:background="@drawable/edit_text_line_contacts"
android:focusable="true"
android:clickable="true"
android:hint="Search..."/>
<requestFocus/>
用于向软键盘显示我在Fragment
中给出的代码
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edt_searchContact, InputMethodManager.SHOW_IMPLICIT);
在清单中
android:windowSoftInputMode="adjustPan"
我在一个Activity
中有3个Fragment
,当一个Fragment
出现时,EditText
将在主Activity
布局中可见。
有没有人能帮我提前谢谢:)
发布于 2015-10-20 13:06:56
在你的活动中尝试一下
editText = (EditText)findViewById(R.id.txt_yourName);
// Request focus and show soft keyboard automatically
editText.requestFocus();
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
发布于 2015-10-20 13:27:06
试试这个:
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
editText.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edt_searchContact, InputMethodManager.SHOW_IMPLICIT);
}
});
}
});
editText.requestFocus();
发布于 2015-10-20 13:27:29
在您的活动的onResume()方法中,您可以编写以下代码:
EditText et = (EditText) findViewById(R.id.et);
et.requestFocus();
InputMethodManager mngr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mngr.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
https://stackoverflow.com/questions/33228325
复制相似问题