简易 的QQ APP登录以及注册页面的实现

1:首页面的效果图

这里写图片描述

XML代码的实现:
这里主要使用了相对布局和线性布局来实现

<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:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    tools:context=".MainActivity" >
    <ImageView 
        android:id="@+id/imageview"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/a1"
        android:layout_centerHorizontal="true"/>
    <LinearLayout 
        android:id="@+id/linearlayout1"
        android:layout_marginTop="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_below="@+id/imageview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="用户名"
            android:textSize="19sp" />

        <EditText 
            android:id="@+id/edittext1"
            android:layout_width="0dip"
            android:layout_weight="3"
            android:layout_height="wrap_content"
            android:hint="QQ/手机号/邮箱"
            android:inputType="text"/>
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/linearlayout2"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
         android:layout_below="@+id/linearlayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text=" 密  码  "
            android:textSize="19sp"/>
         <EditText 
            android:id="@+id/edittext2"
            android:layout_width="0dip"
            android:layout_weight="3"
            android:layout_height="wrap_content"
            android:hint="请输入密码..."
            android:inputType="textPassword"/>
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/linearlayout3"
        android:layout_below="@+id/linearlayout2"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:orientation="horizontal">
       <Button 
           android:id="@+id/button1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginRight="20dp"
           android:text=" 登  录  "

           android:textSize="20sp"/>
        <Button 
           android:id="@+id/button2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text=" 注  册   "

           android:textSize="20sp"/>
    </LinearLayout>
    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearlayout3"
        android:onClick="click"
        android:text="忘记密码"
        android:gravity="left"
        android:layout_marginTop="20dp"/>
</RelativeLayout>

MainActivity.class代码:

package com.kuangjia;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //button2:注册按钮
        findViewById(R.id.button2).setOnClickListener(new OnClickListener() {
            //匿名内部类
            @Override
            public void onClick(View v) {
            //这里是用Intent方法实现的,也可以用setContentView()方法,缺点是在按下返回键时会直接退出程序
                Intent intent=new Intent();
                intent.setClass(MainActivity.this, MainActivity2.class);
                startActivity(intent);

            }
        });
        //button1:登录按钮
        findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
            //匿名内部类
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this, MainActivity3.class);
                startActivity(intent);
            }
        });
    }

//  @Override
//  public boolean onCreateOptionsMenu(Menu menu) {
//      // Inflate the menu; this adds items to the action bar if it is present.
//      getMenuInflater().inflate(R.menu.main, menu);
//      return true;
//  }

}

2:接下来再新建一个注册页面的activity_main2:

注册页面效果图:

这里写图片描述
XML代码的实现:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout 
        android:id="@+id/linearlayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="40dp"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="账户"
            />
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="text"
            android:singleLine="true"
            />
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/linearlayout5"
        android:layout_below="@+id/linearlayout4"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
              android:gravity="center"
            android:text="密码:"/>
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="textPassword"
             android:singleLine="true"
            />
    </LinearLayout>
     <LinearLayout 
        android:id="@+id/linearlayout6"
        android:layout_below="@+id/linearlayout5"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
              android:gravity="center"
            android:text="确认密码:"/>
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="textPassword"
             android:singleLine="true"
            />
    </LinearLayout>

    <LinearLayout 
        android:id="@+id/linearlayout7"
        android:layout_below="@+id/linearlayout6"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
              android:gravity="center"
            android:text="邮箱:"/>
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="textEmailAddress"
             android:singleLine="true"
            />
    </LinearLayout>
     <LinearLayout 
        android:id="@+id/linearlayout8"
        android:layout_below="@+id/linearlayout7"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
              android:gravity="center"
            android:text="电话:"/>
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="phone"
            android:phoneNumber="true"
             android:singleLine="true"
            />
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/linearlayout9"
        android:layout_below="@+id/linearlayout8"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
              android:gravity="center"
            android:text="地址:"/>
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="textPostalAddress"
             android:singleLine="true"
           android:ellipsize="end"
            />
    </LinearLayout>
     <LinearLayout 
        android:id="@+id/linearlayout10"
        android:layout_below="@+id/linearlayout9"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
              android:gravity="center"
            android:text="籍贯:"/>
        <EditText 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:inputType="text"
             android:singleLine="true"
            />
    </LinearLayout>
     <LinearLayout 
        android:id="@+id/linearlayout11"
        android:layout_below="@+id/linearlayout10"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_centerHorizontal="true"
        android:gravity="center">
       <Button 
           android:id="@+id/tijiao"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="提交"
           android:layout_marginRight="20dp"
           android:textSize="18sp"/>
       <Button 
           android:id="@+id/quxiao"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="取消"
           android:textSize="18sp"/>
    </LinearLayout>

</RelativeLayout>

MainActivity2.class代码:

package com.kuangjia;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity2 extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }
}

3:登录按钮后的界面:
效果图:
这里写图片描述
XML代码:

<?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"
    android:orientation="vertical" >
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="功能正在实现中---请等候上线"
        android:layout_margin="20dp"
        android:textSize="18sp"/>

</LinearLayout>

MainActivity3.class代码:

package com.kuangjia;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity3 extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
    }
}

4:最后配置AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kuangjia"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="14" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.kuangjia.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name="com.kuangjia.MainActivity2"/>
        <activity 
            android:name="com.kuangjia.MainActivity3"/>
    </application>

</manifest>
import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.ImageIcon; import javax.swing.*; import java.lang.*; import java.sql.*; class Imagecanvas extends Canvas { Toolkit tool; Image Im; Imagecanvas() { setSize(360, 50); tool = getToolkit(); Im = tool.getImage("dj.jpg"); } public void paint(Graphics g) { g.drawImage(Im, 0, 0, 360, 50, this); } } class QqBorder1 extends JFrame implements ActionListener { Choice cho; QqBorder1() { super("QQ2010"); setSize(360, 260); setLocation(250, 120); setResizable(false); Container c = getContentPane(); FlowLayout layout = new FlowLayout(FlowLayout.CENTER); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); cho = new Choice(); cho.add("在线"); cho.add("隐身"); cho.add("离线"); cho.add("忙碌"); cho.add("请勿打扰"); Imagecanvas canvas1 = new Imagecanvas(); p1.setSize(360, 50); p1.add(canvas1); TextField username = new TextField(25); TextField password = new TextField(25); password.setEchoChar('*'); JButton btrystu = new JButton("登陆"); JButton sezhi = new JButton("设置"); JCheckBox check1 = new JCheckBox("记住密码"); JCheckBox check2 = new JCheckBox("自动登陆"); // p1.setSize(360, 200); JPanel p21 = new JPanel(); JPanel p22 = new JPanel(); p21.add(new JLabel("账号:")); p21.add(username); p21.add(new JLabel("<html><font color=blue>注册新账号</font></html>")); // p21.add(new JLabel(" ")); p21.add(new JLabel("密码:")); p21.add(password); p21.add(new JLabel("<html><font color=blue> 找 回 密 码 </font></html>")); p22.add(new JLabel("状态:")); p22.add(new JLabel(" ")); p22.add(cho); p22.add(check1); p22.add(check2); p22.add(new JLabel(" ")); p2.add(p21); p2.add(p22); p2.setBounds(100, 300, 200, 300); p2.setLayout(new GridLayout(2, 1, 10, 10)); p3.add(sezhi); p3.add(new JLabel(" ")); p3.add(btrystu); add(BorderLayout.NORTH, p1); add(BorderLayout.CENTER, p2); add(BorderLayout.SOUTH, p3); this.setVisible(true); } public void actionPerformed(ActionEvent e) { } } public class QqBorder { }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值