ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

<Android考证之实训项目四>用户注册对话框设计

2019-05-27 12:50:50  阅读:192  来源: 互联网

标签:username 用户注册 对话框 sex intent import 设计 android password


项目截图

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".RegisterActivity">
 9 
10     <TextView
11         android:layout_width="match_parent"
12         android:layout_height="wrap_content"
13         android:text="请输入您的注册信息"
14         android:textSize="24sp" />
15 
16     <LinearLayout
17         android:layout_width="match_parent"
18         android:layout_height="wrap_content"
19         android:orientation="horizontal">
20 
21         <TextView
22             android:layout_width="wrap_content"
23             android:layout_height="wrap_content"
24             android:layout_weight="1"
25             android:text="用户名:"
26             android:textSize="24sp" />
27 
28         <EditText
29             android:id="@+id/username"
30             android:layout_width="wrap_content"
31             android:layout_height="wrap_content"
32             android:layout_weight="1"
33             android:ems="10" />
34     </LinearLayout>
35 
36     <LinearLayout
37         android:layout_width="match_parent"
38         android:layout_height="wrap_content"
39         android:orientation="horizontal">
40 
41         <TextView
42             android:layout_width="wrap_content"
43             android:layout_height="wrap_content"
44             android:layout_weight="1"
45             android:text="密码:"
46             android:textSize="24sp" />
47 
48         <EditText
49             android:id="@+id/password"
50             android:layout_width="wrap_content"
51             android:layout_height="wrap_content"
52             android:layout_weight="1"
53             android:ems="10" />
54     </LinearLayout>
55 
56     <LinearLayout
57         android:layout_width="match_parent"
58         android:layout_height="wrap_content"
59         android:gravity="center"
60         android:orientation="horizontal">
61 
62         <TextView
63             android:layout_width="wrap_content"
64             android:layout_height="wrap_content"
65             android:text="性别:"
66             android:textSize="24sp" />
67 
68         <RadioGroup
69             android:layout_width="wrap_content"
70             android:layout_height="wrap_content"
71             android:layout_weight="1"
72             android:orientation="horizontal">
73 
74             <RadioButton
75                 android:id="@+id/male"
76                 android:layout_width="wrap_content"
77                 android:layout_height="match_parent"
78                 android:layout_marginLeft="100dp"
79                 android:layout_weight="1"
80                 android:text="男" />
81 
82             <RadioButton
83                 android:id="@+id/female"
84                 android:layout_width="wrap_content"
85                 android:layout_height="wrap_content"
86                 android:layout_weight="1"
87                 android:text="女" />
88         </RadioGroup>
89     </LinearLayout>
90 
91     <Button
92         android:id="@+id/register"
93         android:layout_width="match_parent"
94         android:layout_height="wrap_content"
95         android:text="注册" />
96 </LinearLayout>
activity_register.xml
 1 package com.example.register;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.widget.Button;
 8 import android.widget.EditText;
 9 import android.widget.RadioButton;
10 
11 public class RegisterActivity extends AppCompatActivity {
12 
13     private EditText username;
14     private EditText password;
15     private RadioButton male;
16     private RadioButton female;
17     private Button register;
18 
19     @Override
20     protected void onCreate(Bundle savedInstanceState) {
21         super.onCreate(savedInstanceState);
22         setContentView(R.layout.activity_register);
23         username = (EditText)findViewById(R.id.username);
24         password = (EditText)findViewById(R.id.password);
25         male = (RadioButton)findViewById(R.id.male);
26         female = (RadioButton)findViewById(R.id.female);
27         register = (Button)findViewById(R.id.register);
28         register.setOnClickListener(new View.OnClickListener() {
29             @Override
30             public void onClick(View v) {
31                 Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
32                 intent.putExtra("username",username.getText().toString());
33                 intent.putExtra("password",password.getText().toString());
34                 if(male.isChecked()){
35                     intent.putExtra("sex","男");
36                 }
37                 if(female.isChecked()){
38                     intent.putExtra("sex","女");
39                 }
40                 startActivity(intent);
41             }
42         });
43     }
44 }
RegisterActivity.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".MainActivity" >
 9 
10     <TextView
11         android:id="@+id/username"
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:text="您的用户名为:"
15         android:textSize="24sp" />
16 
17     <TextView
18         android:id="@+id/password"
19         android:layout_width="match_parent"
20         android:layout_height="wrap_content"
21         android:text="您的密码为:"
22         android:textSize="24sp" />
23 
24     <TextView
25         android:id="@+id/sex"
26         android:layout_width="match_parent"
27         android:layout_height="wrap_content"
28         android:text="您的性别为:"
29         android:textSize="24sp" />
30 </LinearLayout>
activity_main.xml
 1 package com.example.register;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.widget.TextView;
 7 
 8 public class MainActivity extends AppCompatActivity {
 9 
10     private TextView username;
11     private TextView password;
12     private TextView sex;
13     @Override
14     protected void onCreate(Bundle savedInstanceState) {
15         super.onCreate(savedInstanceState);
16         setContentView(R.layout.activity_main);
17         username = (TextView)findViewById(R.id.username);
18         password = (TextView)findViewById(R.id.password);
19         sex = (TextView)findViewById(R.id.sex);
20         Intent intent = getIntent();
21         username.setText(username.getText().toString()+intent.getStringExtra("username"));
22         password.setText(password.getText().toString()+intent.getStringExtra("password"));
23         sex.setText(sex.getText().toString()+intent.getStringExtra("sex"));
24     }
25 }
MainActivity.java

 

标签:username,用户注册,对话框,sex,intent,import,设计,android,password
来源: https://www.cnblogs.com/jdxb/p/10930059.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有