DBMNG数据库管理与应用

抓住自己最有兴趣的东西,由浅入深,循序渐进地学……
当前位置:首页 > 移动应用 > Android

一个Android登入界面代码

简单的android登入界面:更加详细的介绍请到我的百度经验上面去看http://jingyan.baidu.com/article/dca1fa6f477369f1a44052f7.html
标签: <无>

1. [代码]登入界面     

?
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
<?xml version="1.0"encoding="utf-8"?>
<TableLayout android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_vertical"
    android:stretchColumns="0,3"
    >
    <!-- 第一行 -->
    <TableRow android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView/>
        <TextView android:text="帐    号:"
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:textSize="24px"
            android:layout_height="wrap_content"
            />
        <EditText android:id="@+id/editText1"
            android:textSize="24px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"android:minWidth="200px"/>
        <TextView />
    </TableRow>
    <!-- 第二行 -->
    <TableRow android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView/>
        <TextView android:text="密    码:"
            android:id="@+id/textView2"
            android:textSize="24px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="24px"
            android:id="@+id/editText2"
            android:inputType="textPassword"/>
        <TextView />
    </TableRow>
    <!-- 第3行 -->
    <TableRow android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView/>
        <Button android:text="登录"
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <Button android:text="退出"
            android:id="@+id/exit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <TextView />
    </TableRow>
</TableLayout>

2. [代码]编写登录成功的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
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/nickname"
            android:layout_width="wrap_content"
            android:layout_weight="9"
            android:textSize="24px"
            android:padding="20px"
            android:layout_height="wrap_content"
            android:text="TextView"/>
        <Button
            android:id="@+id/m_exit"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="退出登录"/>
    </LinearLayout>
    <ListView
        android:id="@+id/listView1"
        android:entries="@array/option"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>
</LinearLayout>

3. [代码]编写一个final类,用于保存用户信息:     

?
1
2
3
4
5
6
7
8
packagecom.basillee.asus.myapplication.serversutil;
/**
 * Created by asus on 2015/1/29 0029.
 */
publicfinalclassData {
    publicstaticString[][]USERS={{"0001","123456","basillee"}
            ,{"0002","123456","basillee2"},{"0003","123456","basillee3"}};
}

4. [代码]然后我们编写验证用户输入的账号密码,并且实现跳转到状态页面:     

?
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
private voidtestImitateQQ(){
        Button login=(Button)findViewById(R.id.login);
        Button exit=(Button)findViewById(R.id.exit);
        login.setOnClickListener(newView.OnClickListener() {
            @Override
            publicvoidonClick(View v) {
                String number=((EditText)findViewById(R.id.editText1)).getText().toString();
                String password=((EditText)findViewById(R.id.editText2)).getText().toString();
                booleanflag=false;
                String nickName="";
                for(inti=0;i< Data.USERS.length;i++){
                    if(number.equals(Data.USERS[i][0])){
                        if(password.equals(Data.USERS[i][1])){
                            nickName=Data.USERS[i][2];
                            flag=true;
                            break;
                        }
                    }
                }
                if(flag){
                    Intent intent=newIntent(MainActivity.this,ImitateQQ.class);
                    Bundle bundle=newBundle();
                    bundle.putString("nickName",nickName);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }else{
                    Toast.makeText(getApplicationContext(),"wrong account or password",Toast.LENGTH_LONG).show();
                }
            }
        });
        exit.setOnClickListener(newView.OnClickListener() {
            @Override
            publicvoidonClick(View v) {
                finish();
            }
        });
    }

5. [代码]然后我们编写QQ登录之后的状态页面,接受登录页面传来的用户名并且显示:     

?
1
2
3
4
5
6
7
8
9
10
11
12
Button button=(Button)findViewById(R.id.m_exit);
       button.setOnClickListener(newView.OnClickListener() {
           @Override
           publicvoidonClick(View v) {
               finish();
           }
       });
       Intent intent=getIntent();
       Bundle bundle=intent.getExtras();
       String nickName=bundle.getString("nickName");
       TextView textView=(TextView)findViewById(R.id.nickname);
       textView.setText("User:"+nickName);

6. [图片] QQ截图20150129195728.png    

7. [图片] QQ截图20150129195845.png    

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号