今天分享一下登陆界面用户登录名的检测,大家都知道如果在服务器端进行所有用户名的检测是比较浪费资源的。用户每点击一次登陆就要发到服务端去检测,对于服务端来说负荷是比较大的。所以呢在客服端对用户的非法信息进行简单的过滤是非常有必要的。

源码下载:Android用户名检测
首先看一下效果:
当用户输入的用户名长度小于3,或者大于9时将出现红色提示,并且登陆按钮不可点击。
当输入的用户名大在合法区间则提示消失,如果密码不为空则登陆按钮可点击
虽然功能很小却用到了不少的东西:
接下来看一下源码,为了是登陆界面更加美观,我对登陆控件进行了圆形化处理,也就是开源醒目CircleImageView 项目主页地址:https://github.com/hdodenhof/CircleImageView:
<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:background="@color/colorLogin" > <!-- Login progress --> <ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:visibility="gone" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="180dp" android:id="@+id/head_img" > <de.hdodenhof.circleimageview.CircleImageView android:layout_width="80dp" android:layout_height="80dp" android:src="@mipmap/nav_head" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="25dp" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="20dp" android:orientation="vertical"> <EditText android:id="@+id/et_user" android:layout_width="match_parent" android:layout_height="60dp" android:hint="@string/userName" android:background="@color/colorLoginForm" android:layout_marginBottom="5dp" /> <TextView android:id="@+id/tv_tip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/error" /> <EditText android:id="@+id/et_pass" android:layout_width="match_parent" android:layout_height="60dp" android:background="@color/colorLoginForm" android:hint="@string/passWord" android:paddingTop="1dp" /> </LinearLayout> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/loginButton" android:text="@string/loginButton" android:textColor="@color/colorLoginForm" /> </LinearLayout>
然后修改MainAvtivity.class:
public class MainActivity extends AppCompatActivity {
EditText etUser;
EditText etPassWord;
TextView tvTip;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化View控件
findView();
//用于检测输入的用户名操作
checkLength();
}
private void checkLength() {
//为etUser设置焦点改变监听事件
etUser.setOnFocusChangeListener(new View.OnFocusChangeListener(){
@Override
public void onFocusChange(View v, boolean hasFocus) {
//如果失去焦点则进行用户名的检测
if(etUser.hasFocus()==false){
//如果用户名长度小于3或者大于9,则提示用户名错误且登陆不可点击
if(etUser.getText().toString().length()>9||etUser.getText().toString().length()<3){
tvTip.setText("用户名不合法!");
button.setClickable(false);
}else{
//如果用户名合法且密码不为空,设置提示字体消失按钮可点击
if(etPassWord.getText().toString()!=""){
button.setClickable(true);
tvTip.setText("");
}
}
}
}
});
}
private void findView() {
etUser= (EditText) findViewById(R.id.et_user);
etPassWord= (EditText) findViewById(R.id.et_pass);
tvTip= (TextView) findViewById(R.id.tv_tip);
button= (Button) findViewById(R.id.button);
}
}
整个代码的核心是编辑框的焦点改变的监听,然后对用户名进行判断。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# Android用户名检测
# Android登陆界面用户名检测
# Android登陆用户名检测
# Android开发中实现用户注册和登陆的代码实例分享
# Android实现带有记住密码功能的登陆界面
# Android如何通过手机获取验证码来完成注册功能
# Android设计登录界面、找回密码、注册功能
# Android登录注册功能 数据库SQLite验证
# Android实现登录注册功能封装
# Android实现简易登陆注册逻辑的实例代码
# 看一下
# 服务端
# 为空
# 不合法
# 登陆界面
# 大家都
# 客服
# 我对
# 比较大
# 开源
# 时将
# 登录名
# 大家多多
# 进行了
# 源码下载
# 主页地址
# 却用
# tools
# http
# schemas
相关文章:
宝塔面板如何快速创建新站点?
网站制作企业,网站的banner和导航栏是指什么?
英语简历制作免费网站推荐,如何将简历翻译成英文?
制作国外网站的软件,国外有哪些比较优质的网站推荐?
如何实现建站之星域名转发设置?
建站之星与建站宝盒如何选择最佳方案?
linux top下的 minerd 木马清除方法
相册网站制作软件,图片上的网址怎么复制?
如何高效利用200m空间完成建站?
如何通过PHP快速构建高效问答网站功能?
做企业网站制作流程,企业网站制作基本流程有哪些?
北京网站制作网页,网站升级改版需要多久?
佛山网站制作系统,佛山企业变更地址网上办理步骤?
如何配置支付宝与微信支付功能?
免费网站制作appp,免费制作app哪个平台好?
青浦网站制作公司有哪些,苹果官网发货地是哪里?
如何在香港免费服务器上快速搭建网站?
Swift中循环语句中的转移语句 break 和 continue
临沂网站制作公司有哪些,临沂第四中学官网?
如何快速搭建支持数据库操作的智能建站平台?
如何快速使用云服务器搭建个人网站?
设计网站制作公司有哪些,制作网页教程?
如何高效完成自助建站业务培训?
建站之星如何通过成品分离优化网站效率?
Thinkphp 中 distinct 的用法解析
香港服务器网站搭建教程-电商部署、配置优化与安全稳定指南
宝塔Windows建站如何避免显示默认IIS页面?
如何用VPS主机快速搭建个人网站?
如何用狗爹虚拟主机快速搭建网站?
建站主机系统SEO优化与智能配置核心关键词操作指南
如何选择高效便捷的WAP商城建站系统?
建站主机选虚拟主机还是云服务器更好?
微信推文制作网站有哪些,怎么做微信推文,急?
建站上传速度慢?如何优化加速网站加载效率?
,巨量百应是干嘛的?
金*站制作公司有哪些,金华教育集团官网?
合肥做个网站多少钱,合肥本地有没有比较靠谱的交友平台?
怎么制作一个起泡网,水泡粪全漏粪育肥舍冬季氨气超过25ppm,可以有哪些措施降低舍内氨气水平?
内部网站制作流程,如何建立公司内部网站?
高防网站服务器:DDoS防御与BGP线路的AI智能防护方案
网站制作话术技巧,网站推广做的好怎么话术?
如何将凡科建站内容保存为本地文件?
如何用低价快速搭建高质量网站?
如何在万网自助建站平台快速创建网站?
如何通过免费商城建站系统源码自定义网站主题与功能?
如何选择高性价比服务器搭建个人网站?
如何注册花生壳免费域名并搭建个人网站?
如何在建站之星绑定自定义域名?
小型网站制作HTML,*游戏网站怎么搭建?
如何快速配置高效服务器建站软件?
*请认真填写需求信息,我们会在24小时内与您取得联系。