[英]Automatically get keyboard for an EditText in a Dialog (Android)
Close cousins of this question seem to be all over StackExchange, but maybe that's why I can't find an answer... 这个问题的近亲似乎遍布StackExchange,但这也许就是为什么我找不到答案的原因...
I have an application. 我有一个申请。 Within the application, I've got a couple different Surface Views, and each of them has a couple different actions that fire up a Dialog. 在应用程序中,我有几个不同的“曲面视图”,每个视图都有几个不同的动作,这些动作会触发一个“对话框”。
My dialogs consists of an EditText (for typing in some data) and Set and Cancel buttons for acting on that data. 我的对话框包含一个EditText(用于输入一些数据)以及用于对该数据进行操作的Set和Cancel按钮。 To type in the data, the user first touches the EditText to bring up the keyboard, then types the data, touches Done, then touches Set, and the application continues on its merry way. 要输入数据,用户首先触摸EditText以调出键盘,然后输入数据,触摸Done,然后触摸Set,然后应用程序继续愉快地运行。
I would like to find a way to shorten this, if at all possible. 如果可能的话,我想找到一种缩短此方法的方法。 Specifically, I would like to skip over the view of the dialog and go right to the view of the keyboard. 具体来说,我想跳过对话框的视图,然后转到键盘的视图。 (Essentially, I want to programmatically "touch" the EditText, if that makes any sense.) (本质上,如果有任何意义,我想以编程方式“触摸” EditText。)
Like I said at the beginning of this, I'm not having a lot of luck, so any suggestions will be happily looked in to. 就像我在开始时所说的那样,我运气不太好,因此任何建议都会很高兴地得到关注。 And, unfortunately, simply requesting focus in the EditText has been tried and hasn't done the trick... 而且,不幸的是,仅尝试在EditText中请求焦点,但还没有解决问题的方法...
R. R.
尝试这个
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
The easy and best way , is to give focus to your EditText when your open the dialogues : 最简单,最好的方法是,在打开对话框时将注意力集中在EditText上:
EditText yourET = (EditText) findViewById(R.id.my_editText);
yourET.requestFocus();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.