In Android, how to create EditText of fixed width?

后端 未结 10 470
醉酒成梦
醉酒成梦 2020-12-04 17:52

I would like to create an EditText which accepts only numbers, has a maximum of 4 numbers, and is never narrower than it would be if filled with 4 numbers (does not shrink

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 18:16

    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=match_parent.
    That should make it the right width always.

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

    
    
    
    
    
    
    

提交回复
热议问题