简体   繁体   English

在对话框中自动获取EditText的键盘(Android)

[英]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.

相关问题 Android - 打开软键盘并在没有对话框或布局或编辑文本的情况下获取值 - Android - open soft keyboard and get value without dialog or layout or edittext Android:当焦点在EditText无效时,对话框会自动显示软键盘 - Android: Dialog box show soft keyboard automatically when focus is on an EditText not working Android在带有EditText的对话框上隐藏软键盘 - Android Hide Soft-Keyboard on Dialog with EditText 对话框解雇后未显示android edittext键盘 - android edittext keyboard not showing after dialog dismissal Android:带EditText的AlertDialog不会自动显示键盘 - Android: AlertDialog with EditText does not automatically show the Keyboard Android:EditText会自动打开键盘,如何停止? - Android: EditText turns on keyboard automatically, how to stop? 自动显示EditText的自定义键盘。 Android的 - Automatically show custom keyboard for EditText. Android Dialog Fragment with和EditText在加载后自动显示键盘 - Dialog Fragment with and EditText shows keyboard automatically after load Android-获取EditText并显示对话框 - Android - Get EditText and show dialog 当AlertText对话框中的EditText处于焦点时,Android键盘不显示 - Android keyboard not showing when EditText is in focus, inside Alert Dialog
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM