edittext 手机号、邮箱输入限制、禁止输入--binbinyang

来源:互联网 发布:淘宝店铺页头怎么添加 编辑:程序博客网 时间:2024/06/05 20:07

 今天是2017年1月.真快..就快过年了...说说最近写的代码吧...因为最近做的APP一直类似于OA 钉钉类,所以会去判断输入的文本框,同样会给与限制


public class EdittextDemoActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_edittextdemo);/** * 只能输入数字 */        EditText mEtNum = (EditText) findViewById(R.id.et_num);        mEtNum.setInputType(InputType.TYPE_CLASS_NUMBER);/** * 只能输入电话号码 */        EditText mEtTell = (EditText) findViewById(R.id.et_tell);        mEtTell.setInputType(InputType.TYPE_CLASS_PHONE);//电话        /**         * 邮箱地址         */        EditText mEtEmail = (EditText) findViewById(R.id.et_email);        mEtEmail.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);        /**         * 禁止输入任何文本         *         */        EditText mEtBan = (EditText) findViewById(R.id.et_ban);        mEtBan.setInputType(InputType.TYPE_NULL);        /**         * // 禁止输入(不弹出输入法)上述也是隐藏输入法的一种方式,还有另外一种隐藏办法,         */        EditText mEtBan_other = (EditText) findViewById(R.id.et_ban2);        mEtBan_other.setInputType(InputType.TYPE_NULL);        Toast.makeText(EdittextDemoActivity.this, "焦点改变", Toast.LENGTH_SHORT).show();        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//第一种方法//imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);//第二种方法        imm.hideSoftInputFromWindow(mEtBan_other.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);    }}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              android:layout_width="match_parent"              android:layout_height="match_parent"              android:background="#fff"              android:orientation="vertical"              android:padding="20dp">    <EditText        android:id="@+id/et_num"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:hint="1"/>    <EditText        android:id="@+id/et_tell"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:hint="2"/>    <EditText        android:id="@+id/et_email"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:hint="3"/>    <EditText        android:id="@+id/et_ban"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:hint="4"/>    <EditText        android:id="@+id/et_ban2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:hint="5"/></LinearLayout>


0 0
原创粉丝点击