使android键盘在对话框中自动弹出
我有一个对话框,提示用户输入4位pin码 我希望在显示此对话框片段弹出窗口时自动显示键盘 我试过以下方法,但没有成功使android键盘在对话框中自动弹出,android,android-layout,android-dialog,android-keypad,Android,Android Layout,Android Dialog,Android Keypad,我有一个对话框,提示用户输入4位pin码 我希望在显示此对话框片段弹出窗口时自动显示键盘 我试过以下方法,但没有成功 <EditText android:id="@+id/entercode_dialog_editText_code" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horiz
<EditText
android:id="@+id/entercode_dialog_editText_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:inputType="numberPassword" >
<requestFocus />
</EditText>
尝试以下方法显示键盘:
InputMethodManager imm = (InputMethodManager)getactivity().
getSystemService(Context.INPUT_METHOD_SERVICE);
解决方案1:
if(imm != null){
imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}
解决方案2:
if(imm != null){
imm.showSoftInput(ed, 0);
}
ed在哪里
还有一个解决方案(尚未尝试) 初始化对话框后
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
请尝试显示键盘:
InputMethodManager imm = (InputMethodManager)getactivity().
getSystemService(Context.INPUT_METHOD_SERVICE);
解决方案1:
if(imm != null){
imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}
解决方案2:
if(imm != null){
imm.showSoftInput(ed, 0);
}
ed在哪里
还有一个解决方案(尚未尝试) 初始化对话框后
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
请尝试显示键盘:
InputMethodManager imm = (InputMethodManager)getactivity().
getSystemService(Context.INPUT_METHOD_SERVICE);
解决方案1:
if(imm != null){
imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}
解决方案2:
if(imm != null){
imm.showSoftInput(ed, 0);
}
ed在哪里
还有一个解决方案(尚未尝试) 初始化对话框后
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
请尝试显示键盘:
InputMethodManager imm = (InputMethodManager)getactivity().
getSystemService(Context.INPUT_METHOD_SERVICE);
解决方案1:
if(imm != null){
imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}
解决方案2:
if(imm != null){
imm.showSoftInput(ed, 0);
}
ed在哪里
还有一个解决方案(尚未尝试) 初始化对话框后
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
使用以下命令:-
myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
使用以下命令:-
myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
使用以下命令:-
myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
使用以下命令:-
myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
要显示软键盘,可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
要关闭它,您可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
希望能帮助你出现软键盘,你可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
要关闭它,您可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
希望能帮助你出现软键盘,你可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
要关闭它,您可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
希望能帮助你出现软键盘,你可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
要关闭它,您可以使用
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
希望可以帮助您我在哪里运行此功能?在对话框片段中,“getSystemService()”在片段中不起作用?我的替代方案是什么?哦,对不起,片段你需要getactivity()作为上下文…查看我的更新答案OK很好,现在工作正常,但是有一个小问题,它加载键盘,然后随着对话框加载键盘消失。我认为这是更好的解决方案:覆盖在dialogfragment中创建的Activity,并放置此getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT\u输入\u状态\u可见);我在哪里运行这个?在对话框片段中,“getSystemService()”在片段中不起作用?我的替代方案是什么?哦,对不起,片段你需要getactivity()作为上下文…查看我的更新答案OK很好,现在工作正常,但是有一个小问题,它加载键盘,然后随着对话框加载键盘消失。我认为这是更好的解决方案:覆盖在dialogfragment中创建的Activity,并放置此getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT\u输入\u状态\u可见);我在哪里运行这个?在对话框片段中,“getSystemService()”在片段中不起作用?我的替代方案是什么?哦,对不起,片段你需要getactivity()作为上下文…查看我的更新答案OK很好,现在工作正常,但是有一个小问题,它加载键盘,然后随着对话框加载键盘消失。我认为这是更好的解决方案:覆盖在dialogfragment中创建的Activity,并放置此getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT\u输入\u状态\u可见);我在哪里运行这个?在对话框片段中,“getSystemService()”在片段中不起作用?我的替代方案是什么?哦,对不起,片段你需要getactivity()作为上下文…查看我的更新答案OK很好,现在工作正常,但是有一个小问题,它加载键盘,然后随着对话框加载键盘消失。我认为这是更好的解决方案:覆盖在dialogfragment中创建的Activity,并放置此getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT\u输入\u状态\u可见);