Phone number formatting an EditText in Android

前端 未结 14 918
情深已故
情深已故 2020-12-02 12:03

I am making a simple Address Book app (targeting 4.2) that takes name, address, city, state, zip and phone.

I want to format the phone number input as a phone number

14条回答
  •  独厮守ぢ
    2020-12-02 12:31

    Maybe below sample project helps you;

    https://github.com/reinaldoarrosi/MaskedEditText

    That project contains a view class call MaskedEditText. As first, you should add it in your project.

    Then you add below xml part in res/values/attrs.xml file of project;

    
        
            
            
        
    
    

    Then you will be ready to use MaskedEditText view.

    As last, you should add MaskedEditText in your xml file what you want like below;

    
    

    Of course that, you can use it programmatically.

    After those steps, adding MaskedEditText will appear like below;

    As programmatically, if you want to take it's text value as unmasked, you may use below row;

    maskedEditText.getText(true);
    

    To take masked value, you may send false value instead of true value in the getText method.

提交回复
热议问题