本文来源:http://android.tgbus.com/Android/tutorial/201107/361066.shtml
自定义了Dialog然后弹出软键盘,但是键盘不属于当前活动窗口
代码如下
private View textEntryView;
AlertDialog myDialog = null;
private EditText post;
private void showMyDialog() {
LayoutInflater factory = LayoutInflater.from(this);
textEntryView = factory.inflate(R.layout.managerview, null);
textEntryView.findFocus();
myDialog = new AlertDialog.Builder(this).create();
myDialog.show();
myDialog.getWindow().setContentView(textEntryView);
//关键代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
InputMethodManager imm = (InputMethodManager)
getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(textEntryView, 0); //显示软键盘
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); //显示软键盘
}
自定义了Dialog然后弹出软键盘,但是键盘不属于当前活动窗口
代码如下
private View textEntryView;
AlertDialog myDialog = null;
private EditText post;
private void showMyDialog() {
LayoutInflater factory = LayoutInflater.from(this);
textEntryView = factory.inflate(R.layout.managerview, null);
textEntryView.findFocus();
myDialog = new AlertDialog.Builder(this).create();
myDialog.show();
myDialog.getWindow().setContentView(textEntryView);
//关键代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
InputMethodManager imm = (InputMethodManager)
getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(textEntryView, 0); //显示软键盘
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); //显示软键盘
}