如何显示/隐藏对话框Android的软键盘? [英] How to show/hide the Android Soft Keyboard in dialog?
本文介绍了如何显示/隐藏对话框Android的软键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序定制对话框中BaseExpandableListAdapter类。
在对话框中,我有两个编辑文本。首先是名字和它的强制性。其次是解决其可选的。和两个按钮确定和取消。当对话框显示我想要显示键盘的请求焦点编辑文本的名称。单击OK按钮软键盘应该得到隐藏后。
解决方案
最后对话的对话=新的对话框(_context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);dialog.setContentView(R.layout.prompts);
。dialog.getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);最终的EditText名=(EditText上)dialog.findViewById(R.id.name);
最终的EditText添加=(EditText上)dialog.findViewById(R.id.add);按钮btnok =(按钮)dialog.findViewById(R.id.btn_ok);
按钮btncancel =(按钮)dialog.findViewById(R.id.btn_cancel); btnAddExpList.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){dialog.getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)。
}
}
In my application custom dialog is in BaseExpandableListAdapter class. In dialog I have two edit text. First is name and its mandatory. And second is address its optional. And two buttons OK and cancel. When Dialog shows I want to show keyboard with request focus for edit text name. After clicking of OK button Soft Keyboard should get hide.
解决方案
final Dialog dialog = new Dialog(_context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.prompts);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
final EditText name = (EditText) dialog.findViewById(R.id.name);
final EditText add = (EditText) dialog.findViewById(R.id.add);
Button btnok = (Button) dialog.findViewById(R.id.btn_ok);
Button btncancel = (Button) dialog.findViewById(R.id.btn_cancel);
btnAddExpList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
}
这篇关于如何显示/隐藏对话框Android的软键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文