一、添加部分控件完善登入过程
① 设计应用登录界面加入ImageView
在login_layout.xml中加入以下代码
<?xml version="1.0" encoding="utf-8"?>
<!-- 此Activity采用相对布局 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
...
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/timg"/>
</RelativeLayout>
② 设计应用登录界面登录时加入ProgresDialog
修改LoginActivity中代码
...
login.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
...
ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setTitle("正在登陆");
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(true);
progressDialog.show();
//创建Intent对象,传入源Activity和目的Activity的类对象
Intent intent = new Intent(LoginActivity.this, SuccessActivity.class);
//启动Activity
startActivity(intent);
}
}); .
③ 设计注册页面的注册确认加上AlertDialog
添加RegistActivity处对注册确定按钮的代码
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder dialog = new AlertDialog.Builder(RegistActivity.this);
dialog.setTitle("Attention:");
dialog.setMessage("确认要进行注册么");
dialog.setCancelable(false);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText username = (EditText)findViewById(R.id.username);
EditText password = (EditText)findViewById(R.id.password);
//判断用户注册是否输入了密码和用户名
//首先学会如何判断EditText中内容为空,要包含trim(去掉首部空格)

本文档详细介绍了EChat简易聊天项目的聊天界面UI实现过程,包括登录界面的优化,如添加ImageView和ProgressDialog,注册确认的AlertDialog设计。在聊天功能上,使用SuccessActivity作为聊天界面,通过Gradle添加依赖库,定制msg_item.xml布局,创建MsgAdapter适配器,并为RecyclerView设置数据及发送按钮事件响应。

3255

被折叠的 条评论
为什么被折叠?



