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

发布于 2024-12-09 18:09:15 字数 435 浏览 0 评论 0原文

这个问题的近亲似乎遍布 StackExchange,但也许这就是为什么我找不到答案......

我有一个应用程序。在应用程序中,我有几个不同的表面视图,每个视图都有几个不同的操作来启动对话框。

我的对话框由一个 EditText(用于输入某些数据)以及用于对该数据进行操作的“设置”和“取消”按钮组成。要输入数据,用户首先触摸 EditText 以调出键盘,然后输入数据,触摸“完成”,然后触摸“设置”,应用程序将继续其愉快的运行方式。

如果可能的话,我想找到一种方法来缩短这个时间。具体来说,我想跳过对话框视图并直接转到键盘视图。 (本质上,我想以编程方式“触摸”EditText,如果这有意义的话。)

就像我在开头所说的那样,我没有太多运气,所以任何建议都会很高兴地得到考虑。而且,不幸的是,已经尝试过简单地在 EditText 中请求焦点,但没有成功......

R.

Close cousins of this question seem to be all over StackExchange, but maybe that's why I can't find an answer...

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. 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.

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.)

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...

R.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无敌元气妹 2024-12-16 18:09:15

试试这个

 dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Try this

 dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
乖乖公主 2024-12-16 18:09:15

最简单且最好的方法是在打开对话框时将焦点放在 EditText 上:

EditText yourET = (EditText) findViewById(R.id.my_editText);
yourET.requestFocus();

The easy and best way , is to give focus to your EditText when your open the dialogues :

EditText yourET = (EditText) findViewById(R.id.my_editText);
yourET.requestFocus();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文