开发者

How do you make an EditText whose original text can only be fully changed?

开发者 https://www.devze.com 2023-01-08 17:19 出处:网络
In the Google Maps app, there\'s a unique EditText that I\'d like to reproduce.If you click \"menu\" then go to \"directions\", the \"start point\" field should begin with \"My Location\" as the text.

In the Google Maps app, there's a unique EditText that I'd like to reproduce. If you click "menu" then go to "directions", the "start point" field should begin with "My Location" as the text. The interesting part of this field is its behavior - you cannot edit "My Location" without completely deleting it first.

I have a few places whe开发者_C百科re such behavior would be useful, but I can never quite fully reproduce this. There are three challenges involved with this behavior:

  1. No matter what the user does, they cannot partially edit the field; it is always fully selected.

  2. The keyboard directional keys, rather than moving around the EditText field, change focus.

  3. When the user does choose to change the text, the behavior of #1 and #2 disappear and the field acts like a normal EditText.

Has anyone ever successfully reproduced this behavior?


Isn't it just a hint? Try setting

android:hint="My Location"

on the EditText in your layout resources.

0

精彩评论

暂无评论...
验证码 换一张
取 消