在Android中,如何创建固定宽度的EditText?宽度、Android、EditText

2023-09-03 21:39:28 作者:茫然不知崩溃

我想创建一个EditText只节选数字,最多有4个数字,并且永远不会窄于仿佛充满了4号这将是(不空当缩小,或有扩大,以容纳4号......是固定的。)

I would like to create an EditText which only excepts numbers, has a maximum of 4 numbers, and is never narrower than it would be if filled with 4 numbers (does not shrink when empty, or have to expand to accommodate 4 numbers... is fixed.)

第2完成用:机器人:inputType =数字和android:最大长度=4。如何设置的最小长度?

The first 2 are accomplished with: android:inputType="number" and android:maxLength="4". How can I set the minimum length?

感谢你。

推荐答案

小的hackish ,但你可以把你的的EditText 在< $ C C>的FrameLayout $旁边另一个的TextView 文本=0000的知名度=不可见的。 的FrameLayout 应该有宽度= WRAP_CONTENT 和您的的EditText 宽度= FILL_PARENT 。照片,应该使之正确的宽度总是这样。

A little hackish, but you can put your EditText inside a FrameLayout alongside with another TextView with text="0000" and visibility=invisible.FrameLayout Should have width=wrap_content and your EditText will have width=fill_parent.That should make it the right width always.

这样做的好处是,它是100%的XML端,没有code参与。

The advantage of this is, it's 100% xml-side, no code involved.