安卓仿QQ界面
程序员文章站
2022-08-03 11:37:58
新建空的活动页面JAVA代码:import android.app.ProgressDialog;import android.content.Intent;import android.os.Bundle;import android.os.SystemClock;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.CheckBox;i...
新建空的活动页面
JAVA代码:
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.llk_qq.user.Register;
import com.example.llk_qq.user.UserDB;
import com.example.llk_qq.user.user;
public class Login extends AppCompatActivity implements View.OnClickListener {
private UserDB userDB;
private user user;
private EditText account2, pwd;
private CheckBox remember;
private Button LoginButton, RegistButton;
private TextView alluser;
private ProgressBar progressBar;
ProgressDialog prodialog;
public static final String TAG = com.example.llk_qq.Login.class.getName();
private ImageView iv_showCode;
private EditText et_phoneCode;
private EditText et_phoneNum;
//产生的验证码
private String realCode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
account2=findViewById(R.id.accountedit);
pwd=findViewById(R.id.passwordedit);
iv_showCode = (ImageView) findViewById(R.id.iv_showCode);
//将验证码用图片的形式显示出来
iv_showCode.setImageBitmap(com.example.llk_qq.Code.getInstance().createBitmap());
realCode = com.example.llk_qq.Code.getInstance().getCode().toLowerCase();
iv_showCode.setOnClickListener(this);
final ProgressDialog dialog = new ProgressDialog(this);
et_phoneCode = (EditText) findViewById(R.id.et_phoneCodes);
Button button1 = (Button) findViewById(R.id.go);
button1.setOnClickListener(this);
Button button2 = (Button) findViewById(R.id.add);
Button button3 = (Button) findViewById(R.id.forget);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(com.example.llk_qq.Login.this, Register.class);
startActivity(intent);
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(com.example.llk_qq.Login.this, com.example.llk_qq.FindPwd.class);
startActivity(intent);
}
});
}
@Override
public void onClick(View v) {
userDB =new UserDB();
userDB.OpenUserDb(this);
String account, password;
account=account2.getText().toString();
password=pwd.getText().toString();
user = userDB.findUserByAccout(account);
switch (v.getId()) {
case R.id.iv_showCode:
iv_showCode.setImageBitmap(com.example.llk_qq.Code.getInstance().createBitmap());
realCode = com.example.llk_qq.Code.getInstance().getCode().toLowerCase();
Log.v(TAG, "realCode" + realCode);
break;
case R.id.go:
String phoneCode = et_phoneCode.getText().toString().toLowerCase();
if (user == null) {
Toast.makeText(this, "账号不存在", Toast.LENGTH_SHORT).show();
return;
} else if(!account.equals(user.getAccount()) || !password.equals(user.getPassword())){
Toast.makeText(this, "账号或密码错误", Toast.LENGTH_SHORT).show();
}else if(!phoneCode.equals(realCode)){
Toast.makeText(this, "验证码错误", Toast.LENGTH_SHORT).show();
}
else if (account.equals(user.getAccount())&&password.equals(user.getPassword())&&phoneCode.equals(realCode)) {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("正在登录,请稍后...");
// 设置一下进度条的样式
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// 最后一步一定要记得show 出来
dialog.show();
// 创建一个子线程
new Thread() {
public void run() {
// 设置进度条最大值
dialog.setMax(100);
// 设置当前进度
for (int i = 0; i <= 100; i++) {
dialog.setProgress(i);
// 睡眠一会
SystemClock.sleep(20);
}
// 关闭对话框
dialog.dismiss();
Intent intent = new Intent(com.example.llk_qq.Login.this, com.example.llk_qq.User.class);
intent.putExtra("account",user.getAccount());
intent.putExtra("name",user.getName());
intent.putExtra("age",user.getAge());
intent.putExtra("sex",user.getSex());
intent.putExtra("psd",user.getPassword());
startActivity(intent);
};
}.start();
} else {
Toast.makeText(com.example.llk_qq.Login.this, phoneCode + "验证码错误", Toast.LENGTH_SHORT).show();
}
break;
}
}
}
XML代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:background="@drawable/qq"
android:id="@+id/qq"
android:layout_marginTop="20dp"
android:layout_marginLeft="100dp"
android:layout_width="200dp"
android:layout_height="150dp"
/>
<EditText
android:id="@+id/accountedit"
android:layout_width="300dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:background="@drawable/input"
android:gravity="center"
android:hint="QQ号/手机号/邮箱"
android:textSize="23dp"></EditText>
<EditText
android:id="@+id/passwordedit"
android:background="@drawable/input"
android:hint="密码"
android:textSize="23dp"
android:gravity="center"
android:layout_marginLeft="58dp"
android:layout_width="300dp"
android:layout_marginTop="20dp"
android:layout_height="60dp"></EditText>
<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<EditText
android:id="@+id/et_phoneCodes"
android:layout_width="200dp"
android:layout_height="50dp"
android:background="@null"
android:hint="请输入右侧验证码"
android:gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
/>
<ImageView
android:id="@+id/iv_showCode"
android:layout_width="100dp"
android:layout_marginLeft="30dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"/>
</LinearLayout>
<Button
android:id="@+id/go"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_below="@id/passwordedit"
android:layout_marginTop="30dp"
android:layout_marginLeft="180dp"
android:background="@drawable/go"
android:onClick="go"/>
<Button
android:id="@+id/forget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/go"
android:layout_marginLeft="120dp"
android:layout_marginTop="100dp"
android:background="#00000000"
android:text="忘记密码" />
<Button
android:id="@+id/add"
android:background="#00000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_below="@id/go"
android:layout_marginTop="-48dp"
android:text="用户注册"/>
</LinearLayout>
</RelativeLayout>
实际功能
本文地址:https://blog.csdn.net/saigaolang/article/details/107116373
上一篇: 北京于谦祠