Mask EditText

Links & Dependenciesactivity_main.xmlMainActivity.java

Library on GitHub with dependencies + instructions:

github.com/santalu/mask-edittext

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.codinginflow.maskedittext.MainActivity">

    <com.santalu.maskedittext.MaskEditText
        android:id="@+id/edit_text_phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Phone Number"
        android:inputType="phone"
        app:met_mask="+49(###) ### ## ##" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showText"
        android:text="Show Text" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showRawText"
        android:text="Show raw Text" />

</LinearLayout>
package com.codinginflow.maskedittext;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.santalu.maskedittext.MaskEditText;

public class MainActivity extends AppCompatActivity {
    private MaskEditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.edit_text_phone);
    }

    public void showText(View v) {
        Toast.makeText(this, editText.getText(), Toast.LENGTH_SHORT).show();
    }

    public void showRawText(View v) {
        Toast.makeText(this, editText.getRawText(), Toast.LENGTH_SHORT).show();
    }
}