当你的才华还撑不起你的梦想时,你只能一直前进!

模拟QQ聊天系统-安卓源代码

利用课余时间随便写的一个小东西,都是一起学习。

先上图:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.example.nanchen.listviewdemo.adapter;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
 
import com.example.nanchen.listviewdemo.adapter_content.Msg;
import com.example.nanchen.listviewdemo.R;
 
import java.util.List;
 
/**
 * Created by nanchen on 2016/3/28.
 *
 */
public class MsgAdapter extends ArrayAdapter<Msg> {
    private int resourceId;
 
    public MsgAdapter(Context context, int resource, List<Msg> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Msg msg = getItem(position);
        viewHolder viewHolder;
        if(convertView == null){
            convertView = LayoutInflater.from(getContext()).inflate(resourceId,null);
            viewHolder = new viewHolder();
            viewHolder.leftLayout = (LinearLayout) convertView.findViewById(R.id.left_layout);
            viewHolder.rightLayout = (LinearLayout) convertView.findViewById(R.id.right_layout);
            viewHolder.leftMsg = (TextView) convertView.findViewById(R.id.left_msg);
            viewHolder.rightMsg = (TextView) convertView.findViewById(R.id.right_msg);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (MsgAdapter.viewHolder) convertView.getTag();
        }
        if (msg.getType() == Msg.TYPE_RECEIVED){//若是收到的消息,则隐藏右布局,显示左布局
            viewHolder.leftLayout.setVisibility(View.VISIBLE);
            viewHolder.rightLayout.setVisibility(View.GONE);
            viewHolder.leftMsg.setText(msg.getContent());
        }else if(msg.getType() == Msg.TYPE_SENT){
            viewHolder.leftLayout.setVisibility(View.GONE);
            viewHolder.rightLayout.setVisibility(View.VISIBLE);
            viewHolder.rightMsg.setText(msg.getContent());
        }
        return convertView;
    }
    class viewHolder{
        LinearLayout leftLayout;
        LinearLayout rightLayout;
        TextView leftMsg;
        TextView rightMsg;
    }
}

  

复制代码
package com.example.nanchen.listviewdemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.nanchen.listviewdemo.adapter_content.Person;
import com.example.nanchen.listviewdemo.R;

import java.util.List;

/**
 *
 * Created by nanchen on 2016/3/22.
 */
public class PersonAdapter extends ArrayAdapter<Person> {

    private int resourceId;

    public PersonAdapter(Context context, int textViewResourceId, List<Person> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Person person = getItem(position);
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = LayoutInflater.from(getContext()).inflate(resourceId ,null);
            viewHolder = new ViewHolder();
            viewHolder.imageView_person = (ImageView) convertView.findViewById(R.id.imageView_person);
            viewHolder.textView_name = (TextView) convertView.findViewById(R.id.textView_name);
            convertView.setTag(viewHolder);
        }else{
            //            view = convertView;
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.imageView_person.setImageResource(person.getImageId());
        viewHolder.textView_name.setText(person.getName());
        return convertView;
    }

    class ViewHolder{
        ImageView imageView_person;
        TextView textView_name;
    }
}
复制代码
复制代码
package com.example.nanchen.listviewdemo.adapter_content;

/**
 * Created by nanchen on 2016/3/28.
 * 存储消息类型和内容的类
 */
public class Msg {
    public static final int TYPE_RECEIVED = 0;
    public static final int TYPE_SENT = 1;
    private String content;
    private int type;

    public Msg(String content, int type) {
        this.content = content;
        this.type = type;
    }

    public String getContent() {
        return content;
    }

    public int getType() {
        return type;
    }
}
复制代码
复制代码
package com.example.nanchen.listviewdemo.adapter_content;

/**
 * Created by nanchen on 2016/3/22.
 */
public class Person {
    private String name;
    private int imageId;

    public Person(String name, int imageId) {
        this.name = name;
        this.imageId = imageId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getImageId() {
        return imageId;
    }

    public void setImageId(int imageId) {
        this.imageId = imageId;
    }
}
复制代码
复制代码
 1 package com.example.nanchen.listviewdemo.data;
 2 
 3 import android.os.Parcel;
 4 import android.os.Parcelable;
 5 
 6 /**
 7  *
 8  * Created by nanchen on 2016/3/22.
 9  */
10 public class User implements Parcelable {
11 
12     private String userName;
13     private String pwd;
14 
15     public String getPwd() {
16         return pwd;
17     }
18 
19     public void setPwd(String pwd) {
20         this.pwd = pwd;
21     }
22 
23     public String getUserName() {
24         return userName;
25     }
26 
27     public void setUserName(String userName) {
28         this.userName = userName;
29     }
30 
31     @Override
32     public int describeContents() {
33         return 0;
34     }
35 
36     @Override
37     public void writeToParcel(Parcel dest, int flags) {
38         dest.writeString(userName);
39         dest.writeString(pwd);
40     }
41 
42     //对象的创建器
43     public static final Parcelable.Creator<User> CREATOR = new Parcelable.Creator<User>(){
44 
45 
46         @Override
47         public User createFromParcel(Parcel source) {
48             User user = new User();
49             user.userName = source.readString();
50             user.pwd = source.readString();
51             return user;
52         }
53 
54         @Override
55         public User[] newArray(int size) {
56             return new User[0];
57         }
58     };
59 }
复制代码
复制代码
 1 package com.example.nanchen.listviewdemo;
 2 
 3 import android.app.Activity;
 4 
 5 import java.util.ArrayList;
 6 import java.util.List;
 7 
 8 /**
 9  * Created by nanchen on 2016/3/28.
10  * 退出程序的最佳方案,写一个活动收集器
11  */
12 public class ActivityCollector {
13     public static List<Activity> activities = new ArrayList<>();
14 
15     public static void addActivity(Activity activity){
16         activities.add(activity);
17     }
18 
19     public static void removeActivity(Activity activity){
20         activities.remove(activity);
21     }
22 
23     public static void finishAll(){
24         for (Activity activity:activities){
25             if (!activity.isFinishing()){
26                 activity.finish();
27             }
28         }
29     }
30 }
复制代码
复制代码
 1 package com.example.nanchen.listviewdemo;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.util.Log;
 6 
 7 /**
 8  * Created by nanchen on 2016/3/28.
 9  * 用于知晓当前是在哪一个活动
10  * 活动的最佳写法
11  */
12 public class BaseActivity extends Activity {
13     @Override
14     protected void onCreate(Bundle savedInstanceState) {
15         super.onCreate(savedInstanceState);
16         Log.d("BaseActivity", getClass().getSimpleName());
17         ActivityCollector.addActivity(this);
18     }
19 
20     @Override
21     protected void onDestroy() {
22         super.onDestroy();
23         ActivityCollector.removeActivity(this);
24     }
25 }
复制代码
复制代码
package com.example.nanchen.listviewdemo;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.nanchen.listviewdemo.adapter.MsgAdapter;
import com.example.nanchen.listviewdemo.adapter_content.Msg;

import java.util.ArrayList;
import java.util.List;

public class ChatActivity extends BaseActivity {

    private ListView listView_msg;
    private EditText editText_input;
    private Button button_send,button_back,button_add;
    private MsgAdapter msgAdapter;
    private List<Msg> msgList = new ArrayList<>();
    private TextView textView_person_name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);

        initMsg();
        msgAdapter = new MsgAdapter(this,R.layout.msg_item,msgList);
        listView_msg = (ListView) findViewById(R.id.listView_msg);
        listView_msg.setAdapter(msgAdapter);

        editText_input = (EditText) findViewById(R.id.editText_send);
        editText_input.clearFocus();
        button_send = (Button) findViewById(R.id.button_send);
        button_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = editText_input.getText().toString();
                if(content.isEmpty()){//用户输入消息为空,则弹出一个警告框
                    final AlertDialog.Builder builder = new AlertDialog.Builder(ChatActivity.this);
                    builder.setTitle("警告");
                    builder.setMessage("输入的消息不能为空!");
                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    builder.show();
                }else{
                    Msg msg = new Msg(content,Msg.TYPE_SENT);
                    msgList.add(msg);
                    msgAdapter.notifyDataSetChanged();//当有新消息时,刷新ListView中的显示
                    listView_msg.setSelection(msgList.size());//将ListView定位到最后一行
                    editText_input.setText("");//清空输入框中的内容

                }
            }
        });

        button_back = (Button) findViewById(R.id.button_back);
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        button_add = (Button) findViewById(R.id.button_add);
        button_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ChatActivity.this,"你点击了添加按钮!!!",Toast.LENGTH_SHORT).show();
            }
        });

        textView_person_name = (TextView) findViewById(R.id.textView_person_name);
        Intent intent = getIntent();
        String person_name = intent.getStringExtra("PERSON_NAME");
        textView_person_name.setText(person_name);
    }

    private void initMsg() {
        Msg msg = new Msg("Hello!",Msg.TYPE_SENT);
        msgList.add(msg);
        Msg msg1 = new Msg("Hello!How are you?",Msg.TYPE_RECEIVED);
        msgList.add(msg1);
        Msg msg2 = new Msg("I am fine,and you?",Msg.TYPE_SENT);
        msgList.add(msg2);
        Msg msg3 = new Msg("I am ok!",Msg.TYPE_RECEIVED);
        msgList.add(msg3);
    }
}
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.example.nanchen.listviewdemo;
 
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
 
import com.example.nanchen.listviewdemo.data.User;
 
public class LoginActivity extends BaseActivity {
 
    private EditText editText_userName,editText_pwd;
    private CheckBox checkBox_pwd,checkBox_autoLogin;
    private SharedPreferences sp;
    private ImageButton imageButton_exit;
    private Button button_login;
    private String userName,pwd;
    private Button button_regist;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
 
        //获得实例对象
        sp = this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        editText_userName = (EditText) findViewById(R.id.editText_userName);
        editText_pwd = (EditText) findViewById(R.id.editText_pwd);
        imageButton_exit = (ImageButton) findViewById(R.id.ib_exit);
        button_login = (Button) findViewById(R.id.button_login);
        checkBox_autoLogin = (CheckBox) findViewById(R.id.checkBox_autoLogin);
        checkBox_pwd = (CheckBox) findViewById(R.id.checkBox_pwd);
        button_regist = (Button) findViewById(R.id.button_regist1);
 
 
        //判断记住密码框状态
        if(sp.getBoolean("ISCHECK",false)){//false是默认值
            //设置默认是选择状态
            checkBox_pwd.setChecked(true);
            userName = sp.getString("USER_NAME","");
            pwd = sp.getString("PWD","");
            editText_userName.setText(userName);
            editText_pwd.setText(pwd);
 
            //判断自动登录复选框状态
            if(sp.getBoolean("AUTO_ISCHECK",false)){
 
                //设置自动登录框状态
                checkBox_autoLogin.setChecked(true);
 
                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
            }
        }
 
 
        button_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userName = editText_userName.getText().toString();
                pwd = editText_pwd.getText().toString();
 
                if(TextUtils.isEmpty(userName) || TextUtils.isEmpty(pwd)){//如果用户名或者密码为空
                    Toast.makeText(LoginActivity.this, "用户名或密码不能为空!", Toast.LENGTH_SHORT).show();
                }else {
                    if(userName.equals("liushilin") && pwd.equals("luochunyan")){
                        Toast.makeText(LoginActivity.this,"登录成功!正在获取用户信息...",Toast.LENGTH_SHORT).show();
 
                        //如果用户选择记住密码,则把用户信息存在xml文件中
                        if(checkBox_pwd.isChecked()){
                            SharedPreferences.Editor editor = sp.edit();
                            editor.putString("USER_NAME",userName);
                            editor.putString("PWD",pwd);
                            editor.commit();
                        }
 
                        //主界面的跳转
                        Intent intent = new Intent(LoginActivity.this,MainActivity.class);
 
                        //                        intent.putExtra("USER_NAME",userName);
                        //                        intent.putExtra("PWD",pwd);
 
                        User user = new User();
                        user.setUserName(userName);
                        user.setPwd(pwd);
 
                        intent.putExtra("USER",user);
 
                        startActivity(intent);
                    }else{
                        Toast.makeText(LoginActivity.this,"用户名或密码不正确,请重新输入!",Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
 
        //监听记住密码复选框的按钮事件
        checkBox_pwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = sp.edit();
                if(checkBox_pwd.isChecked()){
                    editor.putBoolean("ISCHECK", true).commit();
                }else{
                    editor.putBoolean("ISCHECK",false).commit();
                }
 
            }
        });
 
        //监听自动登录按钮事件
        checkBox_autoLogin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(checkBox_autoLogin.isChecked()){
                    sp.edit().putBoolean("AUTO_ISCHECK",true).commit();
                }else {
                    sp.edit().putBoolean("AUTO_ISCHECK",false).commit();
                }
            }
        });
 
        //监听退出按钮事件
        imageButton_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                finish();
                ActivityCollector.finishAll();//退出当前应用程序
            }
        });
 
        button_regist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LoginActivity.this,RegistActivity.class));
            }
        });
    }
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.example.nanchen.listviewdemo;
 
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
 
import com.example.nanchen.listviewdemo.adapter.PersonAdapter;
import com.example.nanchen.listviewdemo.adapter_content.Person;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 使用线程机制模拟下拉加载数据的ListView控件使用
 */
public class MainActivity extends BaseActivity implements AbsListView.OnScrollListener{
    private static final int DATA_UPDATE = 0x1;
    private ListView listView;
    private List<Person> personList = new ArrayList<>();
    private PersonAdapter personAdapter;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        listView = (ListView) findViewById(R.id.listView);
        listView.setOnScrollListener(this);
 
        View footerView = getLayoutInflater().inflate(R.layout.loading_layout,null);
        listView.addFooterView(footerView);
        initData();
 
        personAdapter = new PersonAdapter(this,R.layout.list_item,personList);
        listView.setAdapter(personAdapter);
 
 
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 
//                Toast.makeText(MainActivity.this,"你选择了"+personList.get(position).getName(),Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(MainActivity.this,ChatActivity.class);
                intent.putExtra("PERSON_NAME",personList.get(position).getName());
                startActivity(intent);
            }
        });
 
    }
 
 
    /**
     * 初始化数据
     */
    private void initData(){
        Person person1 = new Person("刘世麟",R.mipmap.a_1);
        personList.add(person1);
        Person person2 = new Person("罗春燕",R.mipmap.a_2);
        personList.add(person2);
        Person person3 = new Person("王足英",R.mipmap.a_3);
        personList.add(person3);
        Person person4 = new Person("蔡何",R.mipmap.a_4);
        personList.add(person4);
        Person person5 = new Person("李兴",R.mipmap.a_5);
        personList.add(person5);
        Person person6 = new Person("李强",R.mipmap.a_6);
        personList.add(person6);
        Person person7 = new Person("李添顺",R.mipmap.a_7);
        personList.add(person7);
        Person person8 = new Person("晏贵秀",R.mipmap.a_8);
        personList.add(person8);
        Person person9 = new Person("周芳",R.mipmap.a_9);
        personList.add(person9);
        Person person10 = new Person("韩思明",R.mipmap.a_10);
        personList.add(person10);
        Person person11 = new Person("晏蜀杰",R.mipmap.a_11);
        personList.add(person11);
        Person person12 = new Person("马巍乃",R.mipmap.a_12);
        personList.add(person12);
    }
 
 
    private int visibleLastIndex;//用来可显示的最后一条数据的索引
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if(personAdapter.getCount() == visibleLastIndex && scrollState == SCROLL_STATE_IDLE){
            new LoadDataThread().start();
        }
    }
 
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        visibleLastIndex = firstVisibleItem + visibleItemCount - 1;//减去最后一个加载中那条
    }
 
    /**
     * 线程间通信的机制
     */
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case DATA_UPDATE:
                    personAdapter.notifyDataSetChanged();
                    break;
            }
        }
    };
 
    /**
     * 模拟加载数据的线程
     */
    class LoadDataThread extends  Thread{
        @Override
        public void run() {
            initData();
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.sendEmptyMessage(DATA_UPDATE);//通过handler发送一个更新数据的标记
        }
    }
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example.nanchen.listviewdemo;
 
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
 
public class RegistActivity extends BaseActivity {
 
    private Button button_regist;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        button_regist = (Button) findViewById(R.id.button_regist);
        button_regist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(RegistActivity.this);
                builder.setTitle("注册");
                builder.setMessage("确认注册吗?");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(RegistActivity.this, LoginActivity.class));
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(RegistActivity.this, LoginActivity.class));
                    }
                });
                builder.show();
            }
        });
    }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.example.nanchen.listviewdemo;
 
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
 
public class SplashActivity extends BaseActivity {
 
//    private static final int STATR_ACTIVITY = 0x1;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        handler.sendEmptyMessageDelayed(STATR_ACTIVITY,2000);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(SplashActivity.this,LoginActivity.class));
            }
        },3000);
 
 
 
    }
 
//    private Handler handler = new Handler(){
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            switch(msg.what){
//                case STATR_ACTIVITY:
//                    startActivity(new Intent(SplashActivity.this,LoginActivity.class));
//                    break;
//            }
//        }
//    };
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.nanchen.listviewdemo.ChatActivity">
 
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1">
 
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Back"
            android:textAllCaps="false"
            android:id="@+id/button_back"/>
 
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/textView_person_name"
            android:layout_weight="4"
            android:gravity="center"
            />
 
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="+"
            android:textSize="18dp"
            android:id="@+id/button_add"/>
 
    </LinearLayout>
 
    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:id="@+id/listView_msg">
 
    </ListView>
 
    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="0dp">
 
        <EditText
            android:layout_width="0dp"
            android:layout_weight="3"
            android:id="@+id/editText_send"
            android:hint="请输入你想输入的话.."
            android:layout_height="wrap_content"/>
 
        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="发送"
            android:textSize="20dp"
            android:id="@+id/button_send"
            android:layout_height="wrap_content"/>
    </LinearLayout>
 
</LinearLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<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="@mipmap/logo_bg"
                tools:context=".LoginActivity"
              android:weightSum="1">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.53"
        >
 
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ib_exit"
            android:layout_alignParentRight="true"
            android:src="@mipmap/quit"/>
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用 户 名:"
            android:textSize="18dp"
            android:paddingTop="18dp"
            android:id="@+id/textView"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"/>
 
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText_userName"
            android:hint="请输入用户名..."
            android:layout_below="@+id/textView"
            android:layout_alignParentStart="true"
            android:layout_alignEnd="@+id/ib_exit"/>
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密 码:"
            android:textSize="18dp"
            android:id="@+id/textView2"
            android:layout_below="@+id/editText_userName"
            android:layout_alignParentStart="true"/>
 
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:hint="请输入密码..."
            android:ems="10"
            android:id="@+id/editText_pwd"
            android:layout_below="@+id/textView2"
            android:layout_alignParentStart="true"
            android:layout_alignParentEnd="true"/>
 
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="记住密码"
            android:id="@+id/checkBox_pwd"
            android:checked="false"
            android:layout_centerVertical="true"
            android:layout_alignParentStart="true"
            android:layout_marginStart="27dp"/>
 
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="自动登录"
            android:id="@+id/checkBox_autoLogin"
            android:checked="false"
            android:layout_below="@+id/checkBox_pwd"
            android:layout_alignStart="@+id/checkBox_pwd"/>
 
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登录"
            android:id="@+id/button_login"
            android:layout_alignBottom="@+id/checkBox_autoLogin"
            android:layout_toEndOf="@+id/checkBox_pwd"
            android:layout_marginStart="64dp"/>
 
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"
            android:id="@+id/button_regist1"
            android:textAllCaps="false"
            android:layout_alignTop="@+id/button_login"
            android:layout_toEndOf="@+id/button_login"/>
 
 
    </RelativeLayout>
 
</LinearLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="@mipmap/login_bg"
    tools:context="com.example.nanchen.listviewdemo.MainActivity">
 
 
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:dividerHeight="3.1dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        />
</RelativeLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="vertical"
    android:background="@mipmap/login_bg"
    tools:context="com.example.nanchen.listviewdemo.RegistActivity">
 
 
    <LinearLayout
        android:orientation="horizontal"
        android:paddingTop="50dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="113dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true">
 
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="用户名:"
            android:id="@+id/textView"/>
 
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText_name"
            android:layout_weight="1"/>
    </LinearLayout>
 
 
    <LinearLayout
        android:orientation="horizontal"
        android:paddingTop="100dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="113dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:id="@+id/linearLayout">
 
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="密    码:"
            android:id="@+id/textView3"/>
 
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:layout_weight="1"/>
    </LinearLayout>
 
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="完成注册"
        android:id="@+id/button_regist"
        android:layout_marginTop="42dp"
        android:layout_below="@+id/linearLayout"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

  

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="@mipmap/app_start3"
    tools:context="com.example.nanchen.listviewdemo.SplashActivity">
 
</RelativeLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:padding="6dp"
              android:layout_height="match_parent">
 
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView_person"/>
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView_name"/>
</LinearLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
 
    <ProgressBar
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"/>
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="正在玩命加载中..."
        android:id="@+id/textView"/>
</LinearLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:padding="6dp"
              android:orientation="vertical"
              android:layout_height="match_parent">
 
 
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/left_layout"
        android:layout_gravity="left"
        android:background="#c000dd">
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:id="@+id/left_msg"
            android:layout_margin="10dp"
            android:textColor="#fff"
            />
 
    </LinearLayout>
 
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/right_layout"
        android:layout_gravity="right"
        android:background="#00e6ff">
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/right_msg"
            android:layout_gravity="center"
            android:layout_margin="10dp"/>
 
    </LinearLayout>
</LinearLayout>

  

posted @   南尘  阅读(2381)  评论(2编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述

写不完的矫情,做不完的开源

点击进入我的GitHub页
南 尘
主 页
优美钢琴曲合集-南尘.mp3                    感谢您阅读我的博客,如果您现在工作、学习累了或者疲惫了,不妨聆听一下音乐,它能够减轻你的疲劳,还能够带给您一种舒适愉悦的心情。(样式取自博客园-欲泪成雪)
点击右上角即可分享
微信分享提示