简体   繁体   English

单击时如何防止光标将其自身放置在EditText的开头

[英]How do I prevent cursor from placing itself at the beginning of EditText when clicked

I have an EditText pageTitle and its behavior is dependent on its onFocusListener and onClickListener and another method setListenerToRootView() which detects if the soft keyboard is shown or hidden. 我有一个EditText pageTitle和其行为取决于其onFocusListeneronClickListener和另一种方法setListenerToRootView()其检测是否被显示或隐藏软键盘。 The issue is whenever I click pageTitle , the cursor is automatically placed at the beginning. 问题是,每当我单击pageTitle ,光标就会自动放置在开头。 I am suspecting setListenerToRootView() is responsible for this bug since issue fixes itself when I remove this method. 我怀疑setListenerToRootView()是造成此错误的原因,因为删除此方法后问题会自行解决。

However, I do need this method since another view's visibility ( saveCancelBar ) depends on the soft keyboard's visibility. 但是,我确实需要此方法,因为另一个视图的可见性( saveCancelBar )取决于软键盘的可见性。 Is there any way that I can keep this method but make sure that when the user clicks pageTitle , the cursor will be placed on the exact position that he clicked (not the beginning)? 有什么方法可以保留此方法,但是要确保当用户单击pageTitle ,光标将位于其单击的确切位置(而不是开头)?

use setSelection() for selecting the last position programatically. 使用setSelection()以编程方式选择最后一个位置。 in onClick and onFocus use setSelection onClickonFocus使用setSelection

        editTextName.setSelection(editTextName.getText().length());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户键入时,如何防止 EditText 调整自身大小? - How do I prevent an EditText from resizing itself when the user is typing? 单击EditText时如何隐藏显示键盘 - How do i hide the keyboard from showing when EditText is clicked on 如何将光标定位在 EditText 的右侧 - How do I position the cursor on the right in EditText 使用SpannableStringBuilder添加图像跨度后,如何防止光标在EditText(MultiAutoCompleteTextView)中调整大小? - How can I prevent the cursor from resizing in an EditText (MultiAutoCompleteTextView) after I add an imagespan using a SpannableStringBuilder? 如何在 EditText 上隐藏气泡光标? - How do I hide of Bubble cursor on EditText? 如何防止自定义对话框的光标在其中的第一个EditText上闪烁 - How to prevent custom dialog from blinking cursor on first EditText inside of it 在PhoneGap应用程序中单击时,如何防止图像出现被选择? - How do I prevent images from appearing to be selected when clicked in a PhoneGap application? 如何防止Android浮动EditText提示覆盖EditText中的文本? - How do I prevent Android floating EditText hint from covering the text in the EditText? 单击 EditText 时,如何仅显示光标而不显示标准的 Android 键盘? - How do I display only the cursor but not the standard Android keyboard when i click on EditText? IME窗口在Edittext中重叠光标,如何防止呢? - IME window overlap cursor in Edittext, how to prevent it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM