Mask EditText Library in Android

Full project with source code of Mask EditText Library in Android

Dependencies

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.santalu:maskara:1.0.0'
}

activity_main.xml

<?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="tech.codingpoint.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>

MainActivity.java

package tech.codingpoint.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();
    }
}

Leave a Comment