单击非焦点 EditText 时光标位置未更新

发布于 2024-09-28 20:58:11 字数 105 浏览 0 评论 0原文

单击非焦点 EditText 时,它会获得焦点,但光标不会移动到新位置。我应该再次单击它以将光标移动到新位置。

问:如何才能一键聚焦和移动光标?

When non-focused EditText clicked, it becomes focused, but cursor does not move to new location. I should click it again to move cursor to a new position.

Q: How can I focus and move cursor with only one click?

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

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

发布评论

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

评论(1

夏雨凉 2024-10-05 20:58:11

我花了相当多的时间来解决同样的问题,这就是我所做的:

在布局 xml 中,启用 focusable 和 focusableInTouchMode

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:focusable="true" android:focusableInTouchMode="true">
</LinearLayout>

否则,每当软键盘出现时,它都会自动滚动到 EditText 的前面。您可以通过重写“OnFocusChangeListener”来修改位置,但是每次轮询单击的位置有点难看。我将坚持上述更改。

I spent quite some time battling the same problem, and this is what I did:

In your layout xml, enable focusable and focusableInTouchMode

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:focusable="true" android:focusableInTouchMode="true">
</LinearLayout>

Otherwise, whenever the softkeyboard comes up, it automatically scrolls to the front of the EditText. You can modify the position by overriding "OnFocusChangeListener" but it's a little ugly to poll the clicked position every time. I'm going to stick with the change above.

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