EditTextPreference 和默认光标位置
这主要是我的一个小烦恼,但它让我烦恼不已,因为默认行为或 EditTextPreference
是将光标放在字符串的开头。这对我来说毫无意义。在几乎所有其他人类已知的界面中(很好,ME),聚焦于文本字段会自动将光标发送到 END。
所以。有没有一种(简单)方法可以覆盖这个?我知道我可以从 EditTextPreference
扩展并手动调用 setSelection()
,但这对于如此简单的问题来说似乎是一个非常复杂的解决方案。
This is mostly a pet peeve of mine, but it annoys me to no end that the default behavior or EditTextPreference
s is to put the cursor at the beginning of the string. This makes NO sense at all to me. In almost any other interface known to man (fine, ME), focusing on a textfield automatically sends the cursor to the END.
So. Is there an (easy) way to override this? I know I can extend from EditTextPreference
and call setSelection()
manually, but this seems like a really complicated solution for such a simple problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
另一个角度是:我只是在 XML 定义中或以编程方式在对象上将“selectAllOnFocus”设置为 true。
它基本上完成了我想要的:让最终用户能够立即替换内容。
Another angle on this: I just wind up setting 'selectAllOnFocus' to true either in the XML definition, or programmatically on the object.
It basically accomplished what I wanted: to have the end user be able to replace the contents immediately.
与 lukeuser 的解决方案类似,您可以内联定义
OnPreferenceClickListener
或将其定义为类变量:或者
Similar to lukeuser's solution, you can define the
OnPreferenceClickListener
inline or as a class variable:Or
我最终扩展了 EditTextPreference 并覆盖了 showDialog 方法:
I ended up extending
EditTextPreference
and overriding theshowDialog
method:我有另一个解决方案!
然后这适用于您所有的 EditTextPreferences
I got another solution!
Then this for all your EditTextPreferences
这对我来说已经成功了,只需重写
onPreferenceTreeClick()
:请记住,我已经使用了 PreferenceFragment,但它对于 PreferenceActivity 是相同的。
该解决方案改编自 http://www.phonesdevelopers.com/1816051/
This done the trick for me, just override
onPreferenceTreeClick()
:Keep in mind that I have used PreferenceFragment, but it is the same for PreferenceActivity.
This solution is adapted from http://www.phonesdevelopers.com/1816051/