android 身份证号的4到11位用*显示怎么做
2015-12-25 17:23
671 查看
参考以下代码:
布局文件:
运行效果:
![](http://a.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=46e061f8ac773912c4738d67c829aa20/bba1cd11728b471009f1da89c6cec3fdfd03239c.jpg)
点击【显示得完整身份ID】按钮:
![](http://a.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=5099366a90cad1c8d0eef4214f0e4b31/4a36acaf2edda3cc1c0e9e6504e93901203f9288.jpg)
点击【将完整身份ID至编辑框】按钮:
![](http://a.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=ccebc52dc9bf6c81f76224ee8c0e9d0d/b17eca8065380cd7c14a83a8a444ad345982811a.jpg)
package com.sh.xy; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { // 完整身份证 String id = "323218200001010010"; private EditText ed_id; private Button btn_show; private Button btn_show_to_edit; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); ed_id = (EditText) findViewById(R.id.ed_id); btn_show = (Button) findViewById(R.id.show_id); btn_show_to_edit = (Button) findViewById(R.id.show_id_to_edit); // 用于显示的加*身份证 String show_id = id.substring(0, 3) + "********" + id.substring(11); ed_id.setText(show_id); btn_show.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, id, Toast.LENGTH_SHORT).show(); } }); btn_show_to_edit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ed_id.setText(id); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
布局文件:
<LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android"" target="_blank">http://schemas.android.com/apk/res/android"</a> xmlns:tools="<a href="http://schemas.android.com/tools"" target="_blank">http://schemas.android.com/tools"</a> android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.sh.xy.MainActivity" > <include android:id="@+id/top" android:layout_width="match_parent" android:layout_height="wrap_content" layout="@layout/layout_title_bar" /> <EditText android:id="@+id/ed_id" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="显示加*身份ID" /> <Button android:id="@+id/show_id" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="显示完整身份ID" /> <Button android:id="@+id/show_id_to_edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="将完整身份ID至编辑框" /> </LinearLayout>
运行效果:
![](http://a.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=46e061f8ac773912c4738d67c829aa20/bba1cd11728b471009f1da89c6cec3fdfd03239c.jpg)
点击【显示得完整身份ID】按钮:
![](http://a.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=5099366a90cad1c8d0eef4214f0e4b31/4a36acaf2edda3cc1c0e9e6504e93901203f9288.jpg)
点击【将完整身份ID至编辑框】按钮:
![](http://a.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=ccebc52dc9bf6c81f76224ee8c0e9d0d/b17eca8065380cd7c14a83a8a444ad345982811a.jpg)
相关文章推荐
- Android版添加phonegap--Crosswalk插件教程
- Android Studio内存优化
- Android 判断字符串是不是是身份证、邮箱、银行卡、手机号、中文 1
- Android中文API
- android listView 下拉刷新的实现
- 在android项目中简单的集成baidu地图之定位功能
- [Android开发]简单版仿淘口令复制弹出框功能
- Android开发疑难杂症之include布局文件
- Android开发之ListView实现Item局部刷新
- Android使用Font Awesome简单介绍
- Android 打包介绍
- android 图片 高斯模糊 Blur Android Studio JNI NDK 生成 so 问题汇总
- Android开发之关于listview中getView()调用两遍的问题
- Android Studio系列教程(三)
- android Settings开发修改定制
- Android内存泄露分析(MemoryAnalyzer工具)
- Ant多渠道打包
- AndroidStudio快捷键
- android cardview
- Ubuntu下为AndroidStudio编译并使用x264(二)AndroidStudio部分