Android仿QQ登录注册界面_SQlite实现本地缓存
程序员文章站
2022-03-01 12:40:14
...
本Demo是一个高仿QQ登录、注册和修改密码的界面以及找回密码功能、并且带有sqlite数据库缓存数据、封装了sqlite常用的工具类、代码是通过Activity来做的、Layout集成起来非常方便、下面是运行效果图
登录Layout
<RelativeLayout 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" > <RelativeLayout android:id="@ id/loginTop" style="@style/title_relayout" > <TextView android:id="@ id/loginTitle" style="@style/title_text" android:text="@string/login" /> </RelativeLayout> <ImageView android:id="@ id/loginUser" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@ id/loginTop" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:contentDescription="@string/login" android:src="@drawable/user_qq" /> <LinearLayout android:id="@ id/loginli" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@ id/loginUser" android:layout_marginTop="20dp" android:background="#ffffff" android:orientation="vertical" > <EditText android:id="@ id/loginId" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginLeft="20dp" android:background="@null" android:hint="@string/id" android:textColorHint="#CDCDC1" android:textSize="16sp" /> <LinearLayout android:id="@ id/loginline" android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#D7D7D7" android:orientation="vertical" > </LinearLayout> <EditText android:id="@ id/loginPassword" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginLeft="20dp" android:background="@null" android:hint="@string/password" android:inputType="textPassword" android:textColorHint="#CDCDC1" android:textSize="16sp" /> </LinearLayout> <Button android:id="@ id/loginBtn" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@ id/loginli" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:layout_marginBottom="10dp" android:background="@drawable/btnbg" android:includeFontPadding="false" android:text="@string/login" android:textColor="#ffffff" /> <Button android:id="@ id/loginChangePw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@ id/loginBtn" android:includeFontPadding="false" android:background="#00000000" android:layout_alignParentRight="true" android:layout_marginRight="15dp" android:text="@string/changepw" android:textSize="14sp" android:textColor="#00AFEF" /> <Button android:id="@ id/loginMissps" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginLeft="15dp" android:background="#00000000" android:text="@string/misspassword" android:textColor="#00AFEF" android:textSize="14sp" /> <Button android:id="@ id/loginNewUser" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginRight="15dp" android:background="#00000000" android:text="@string/newuser" android:textColor="#00AFEF" android:textSize="14sp" /> </RelativeLayout>
初始化代码
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_login); helper = new MyDatabaseHelper(this); initView(); Intent i = super.getIntent(); String Id = i.getStringExtra("myId"); loginId.setText(Id); } // 控件的初始化 private void initView() { loginId = (EditText) findViewById(R.id.loginId); loginPassword = (EditText) findViewById(R.id.loginPassword); loginBtn = (Button) findViewById(R.id.loginBtn); loginBtn.setOnClickListener(this); loginMissps = (Button) findViewById(R.id.loginMissps); loginMissps.setOnClickListener(this); loginNewUser = (Button) findViewById(R.id.loginNewUser); loginNewUser.setOnClickListener(this); loginChangePw = (Button) findViewById(R.id.loginChangePw); loginChangePw.setOnClickListener(this); }
onClick处理
// 控件的点击事件 @Override public void onClick(View v) { switch (v.getId()) { case R.id.loginBtn: isId = loginId.getText().toString(); isPs = loginPassword.getText().toString(); if (new MyloginCursor( LoginActivity.this.helper.getReadableDatabase()).find(isId) .size() == 0) { // Toast弹窗 Toast.makeText(LoginActivity.this, "手机号未注册,请注册后登录", Toast.LENGTH_SHORT).show(); } else { String lph = new MyloginCursor( LoginActivity.this.helper.getReadableDatabase()).find( isId).toString(); // 对查询出来的数据进行拆分 String result[] = lph.split(","); if (result[1].equals(isId) && result[2].equals(isPs)) { Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(LoginActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show(); } } break; case R.id.loginMissps: Intent a = new Intent(LoginActivity.this, FindPasswordActivity.class); startActivity(a); break; case R.id.loginNewUser: Intent i = new Intent(LoginActivity.this, RegisterActivity.class); startActivity(i); break; case R.id.loginChangePw: Intent l = new Intent(LoginActivity.this, ChangePasswordActivity.class); startActivity(l); break; default: break; } }
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1i3NZ3Ml 密码: 3arr