这是本人第一篇技术博客,当然要原创啦。作为第一篇,说点基础又实用的,EditText,大家都用过,最基本的控件了。在开发过程中,有时为了用户体验,会在EditText输入过程中,追加单位,或者输入证件号时部分变星号这类需求。本文就对此进行讨论。如有更好思路,欢迎指教。
实现思路是双层布局,上面透明输入内容,下面TextView显示内容,需要对EditText的输入进行监听。效果图就不展示了,很简单的输入框,当输入文本时,自动会追加单位。
首先上布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
tools:contex