There is a library developed by jansenfelipe
, you can find a tutorial at this link
more basically you need to add the following dependency:
dependencies {
compile 'br.com.jansenfelipe:androidmask:1.0.1'
}
After this just create the mask as needed:
EditText cpf = (EditText) findViewById(R.id.txtCPF);
EditText tel = (EditText) findViewById(R.id.txtTelefone);
//Mascara cpf
MaskEditTextChangedListener maskCPF = new MaskEditTextChangedListener("###.###.###-##", cpf);
//Mascara Telefone
MaskEditTextChangedListener maskTEL = new MaskEditTextChangedListener("(##)####-####", tel);
The last step is to add this Systener to the field:
cpf.addTextChangedListener(maskCPF);
tel.addTextChangedListener(maskTEL);
With respect to the filled from back to front you can use the setGravity
to point out where the text starts from, for example:
cpf.setGravity(Gravity.RIGHT);
tel.setGravity(Gravity.LEFT);
or in the xml
with the attribute
android:textDirection="rtl"
Here is a partial answer, only need to adapt: https://answall.com/a/207432/35406
– viana