开发者

iphone-style text edit on android

I'm trying to make iPhone-style EditText element on android. The one that will have an additional clear button appear on the right after text input.

Adding a new button is not a problem, but I'm a bit stuck with another thing.

A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?

I want EditText width to be N pixels, and editable area to be N-M pixels.

EditText.setWidth changes width for whole edit box.

EditText.setEllipsize should be the proper solution, 开发者_JAVA百科but docs are empty, and as I see it truncates text based on some String value.

Applying a LengthFilter cut's the input length to number of characters.

Thanks in advance.


I suspect that android:drawableRight will save you a lot of pain.


Seems I've found a solution. EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area


Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/


This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area. This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.

Alternatively you can use the compound drawables, but you would need to implement something like this Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜