Android 开发简易失物招领二手交易平台

一、开发环境

1、android studio(客户端) ,eclipes(服务端)

2、java语言

 

二、效果展示

视频地址:https://www.bilibili.com/video/BV1Ng4y1v7XC/

三、客户端开发

1.首先设置mainactivity为进入的跳转页面,就类似于一个3秒跳转的广告页面。

下面是设置3秒跳转到登录页面的代码。

        final Intent intent=new Intent(this,login_in.class);
        Timer timer=new Timer();
        int DELAY=2*1000;
        TimerTask task=new TimerTask()
        {
            @Override
            public void run(){
                startActivity(intent);
            }
        };
        timer.schedule(task,DELAY);//此处的Delay可以是3*1000,代表三秒

 

另外,如果需要隐藏actionbar,可用以下代码

if(getSupportActionBar()!=null){

            getSupportActionBar().hide();

            getWindow().setFlags(

                    WindowManager.LayoutParams.FLAG_FULLSCREEN,

                    WindowManager.LayoutParams.FLAG_FULLSCREEN

            );

        }

设置actionbar的颜色样式在value/colors.xml中修改

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#33CCFF</color>
    <color name="colorPrimaryDark">#33CCCC</color>
    <color name="colorAccent">#03DAC5</color>
</resources>

2.三秒后跳转到登录页面loginin_in.xml

布局代码如下

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".login_in">

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="363dp"
        android:layout_height="163dp"
        android:layout_marginStart="13dp"
        android:layout_marginLeft="13dp"
        android:layout_marginTop="140dp"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/showview1"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center_horizontal"
            android:text="登录"
            android:textSize="36sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="55dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv1_1"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:ems="10"
                android:gravity="center_horizontal"
                android:inputType="textPersonName"
                android:text="用户名"
                android:textSize="24sp" />

            <EditText
                android:id="@+id/et1_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:hint="请输入用户名"
                android:inputType="textPersonName" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="55dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv1_2"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:ems="10"
                android:gravity="center_horizontal"
                android:inputType="textPersonName"
                android:text="密码"
                android:textSize="24sp" />

            <EditText
                android:id="@+id/et1_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:hint="请输入密码"
                android:inputType="textPassword" />
        </LinearLayout>
    </LinearLayout>

    <Button
        android:id="@+id/loginBt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="104dp"
        android:layout_marginLeft="104dp"
        android:layout_marginTop="39dp"
        android:background="@drawable/bt1"
        android:text="登录"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout" />

    <Button
        android:id="@+id/signinBt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="47dp"
        android:layout_marginLeft="47dp"
        android:layout_marginTop="39dp"
        android:background="@drawable/bt1"
        android:text="注册"
        app:layout_constraintStart_toEndOf="@+id/loginBt"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

在loginin_in.java文件中,刚开始由于服务器上无人注册,需要先注册,点击注册跳转到sign_in.xml中

3.在注册页面,

界面代码跟登录界面相似,就不放了,重点是事件处理方面,点击注册按钮发送注册信息到服务器。

在连接方式时,采取了socket传输数据,在后续处理时,因为服务器需要根据不同的内容发送或接受不同内容,这里在发送时第一位为状态码,总的数据格式为<“state” "username" "userpassword">,这里选取状态码为D,发送过程的代码如下

signinBt.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            String state="I";
                            String sendmsg="";
                            sendmsg="\""+state+"\"    \""+userName.getText()+"\"    \""+userPassword.getText()+"\"";
                            System.out.println("注册语:" + sendmsg);
                            Socket sc = new Socket(HOST, PORT);

                            DataOutputStream outputStream=new DataOutputStream(sc.getOutputStream());

                            try{
                                DataOutputStream  outt;
                                outt=new DataOutputStream(sc.getOutputStream());
                                outt.writeUTF(sendmsg);

                                Log.d("输出到服务器完成", "66 ");
                            }catch(Exception e){
                                Log.d("输出到服务器失败", "00 ");
                            }

                            sc.close();



                        }catch(Exception e){
                            System.out.println("wrong");
                            e.printStackTrace();
                        }
                    }
                }).start();
                showOne();




                //Log.d("11", "onClick: ");
                Intent i = new Intent(sign_in.this , login_i
  • 10
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值