当前位置:   article > 正文

Android:页面的跳转_android登录注册跳转的代码

android登录注册跳转的代码

一:第一步先创建一个项目,名字可以随便取但是首字母要大写

二:在项目里面我划线的地方进行编写代码

 

1:也可以在layout里面进行创建新的项目

点进去后点next 

 

写完之后点击Finish就创建完成了 

三:创建页面

1:先创建一个带有图片的页面

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@drawable/ic_launcher"
  6. tools:context=".BarActivity" >
  7. </LinearLayout>

2:在创建一个可以登录或者注册的页面(这里我写的是注册系统) 

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. tools:context=".MainActivity" >
  7. <TextView
  8. android:layout_width="match_parent"
  9. android:layout_height="80dp"
  10. android:background="#78798a"
  11. android:gravity="center"
  12. android:text="用户注册"
  13. android:textColor="#fff"
  14. android:textSize="35dp" />
  15. <LinearLayout
  16. android:layout_width="match_parent"
  17. android:layout_height="60dp"
  18. android:layout_marginTop="10dp" >
  19. <TextView
  20. android:layout_width="0dp"
  21. android:layout_height="match_parent"
  22. android:layout_weight="1"
  23. android:gravity="right|center"
  24. android:paddingRight="7dp"
  25. android:text="账号:"
  26. android:textSize="20dp" />
  27. <EditText
  28. android:id="@+id/et_username"
  29. android:layout_width="0dp"
  30. android:layout_height="match_parent"
  31. android:layout_marginRight="5dp"
  32. android:layout_weight="3"
  33. android:background="@drawable/main_border"
  34. android:hint="请输入QQ号/手机号"
  35. android:paddingLeft="5dp" />
  36. </LinearLayout>
  37. <LinearLayout
  38. android:layout_width="match_parent"
  39. android:layout_height="60dp"
  40. android:layout_marginTop="10dp" >
  41. <TextView
  42. android:layout_width="0dp"
  43. android:layout_height="match_parent"
  44. android:layout_weight="1"
  45. android:gravity="right|center"
  46. android:paddingRight="7dp"
  47. android:text="密码:"
  48. android:textSize="20dp" />
  49. <EditText
  50. android:id="@+id/et_pwd"
  51. android:layout_width="0dp"
  52. android:layout_height="match_parent"
  53. android:layout_marginRight="5dp"
  54. android:layout_weight="3"
  55. android:background="@drawable/main_border"
  56. android:paddingLeft="5dp" />
  57. </LinearLayout>
  58. <LinearLayout
  59. android:layout_width="match_parent"
  60. android:layout_height="60dp"
  61. android:layout_marginTop="10dp" >
  62. <TextView
  63. android:layout_width="0dp"
  64. android:layout_height="match_parent"
  65. android:layout_weight="1"
  66. android:gravity="right|center"
  67. android:paddingRight="7dp"
  68. android:text="班级:"
  69. android:textSize="20dp" />
  70. <Spinner
  71. android:id="@+id/sp_Item"
  72. android:layout_width="0dp"
  73. android:layout_height="60dp"
  74. android:layout_marginRight="5dp"
  75. android:layout_weight="3" />
  76. </LinearLayout>
  77. <LinearLayout
  78. android:layout_width="match_parent"
  79. android:layout_height="60dp"
  80. android:layout_marginTop="10dp" >
  81. <TextView
  82. android:layout_width="0dp"
  83. android:layout_height="match_parent"
  84. android:layout_weight="1"
  85. android:gravity="right|center"
  86. android:paddingRight="7dp"
  87. android:text="性别:"
  88. android:textSize="20dp" />
  89. <RadioGroup
  90. android:layout_marginRight="5dp"
  91. android:layout_width="0dp"
  92. android:layout_height="match_parent"
  93. android:layout_weight="3"
  94. android:orientation="horizontal" >
  95. <RadioButton
  96. android:id="@+id/rd_M"
  97. android:layout_width="50dp"
  98. android:layout_height="match_parent"
  99. android:text="男" />
  100. <RadioButton
  101. android:id="@+id/rd_W"
  102. android:layout_width="50dp"
  103. android:layout_height="match_parent"
  104. android:text="女" />
  105. </RadioGroup>
  106. </LinearLayout>
  107. <LinearLayout
  108. android:layout_width="match_parent"
  109. android:layout_height="60dp"
  110. android:layout_marginTop="10dp" >
  111. <TextView
  112. android:layout_width="0dp"
  113. android:layout_height="match_parent"
  114. android:layout_weight="1"
  115. android:gravity="right|center"
  116. android:paddingRight="7dp"
  117. android:text="爱好:"
  118. android:textSize="20dp" />
  119. <RadioGroup
  120. android:layout_marginRight="5dp"
  121. android:layout_width="0dp"
  122. android:layout_height="match_parent"
  123. android:layout_weight="3"
  124. android:orientation="horizontal" >
  125. <CheckBox
  126. android:id="@+id/cb_1"
  127. android:layout_width="0dp"
  128. android:layout_height="match_parent"
  129. android:layout_weight="1"
  130. android:text="上网" />
  131. <CheckBox
  132. android:id="@+id/cb_2"
  133. android:layout_width="0dp"
  134. android:layout_height="match_parent"
  135. android:layout_weight="1"
  136. android:text="聊天" />
  137. <CheckBox
  138. android:id="@+id/cb_3"
  139. android:layout_width="0dp"
  140. android:layout_height="match_parent"
  141. android:layout_weight="1"
  142. android:text="睡觉" />
  143. <CheckBox
  144. android:id="@+id/cb_4"
  145. android:layout_width="0dp"
  146. android:layout_height="match_parent"
  147. android:layout_weight="1"
  148. android:text="看书" />
  149. </RadioGroup>
  150. </LinearLayout>
  151. <LinearLayout
  152. android:layout_width="match_parent"
  153. android:layout_height="50dp"
  154. android:layout_marginTop="10dp"
  155. android:gravity="center" >
  156. <Button
  157. android:id="@+id/btn_Commit"
  158. android:layout_width="120dp"
  159. android:layout_height="match_parent"
  160. android:background="@drawable/text_border"
  161. android:text="确定" />
  162. <Button
  163. android:id="@+id/btn_Cancle"
  164. android:layout_width="120dp"
  165. android:layout_height="match_parent"
  166. android:layout_marginLeft="10dp"
  167. android:background="@drawable/text_border"
  168. android:text="取消" />
  169. </LinearLayout>
  170. </LinearLayout>

3:在创建一个可以显示吐丝的页面

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".InfoActivity" >
  10. <TextView
  11. android:id="@+id/tv_show"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:text="@string/hello_world" />
  15. </RelativeLayout>

四:进行连接 

1:找到第一个页面相对应得java代码段并书写代码和第二个(注册页面)进行连接

  1. package com.example.day5;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.view.Menu;
  6. public class BarActivity extends Activity {
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_bar);
  11. Thread t = new Thread(new Runnable() {
  12. @Override
  13. public void run() {
  14. // TODO Auto-generated method stub
  15. try {
  16. Thread.sleep(3000);
  17. } catch (InterruptedException e) {
  18. // TODO Auto-generated catch block
  19. e.printStackTrace();
  20. }
  21. Intent it = new Intent(getApplicationContext(), MainActivity.class);
  22. startActivity(it);
  23. }
  24. });
  25. t.start();
  26. }
  27. }

 2:第一个和第二个页面进行连接(找到第二个java代码段和上面一样)

  1. package com.example.day5;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.view.View;
  6. import android.view.WindowManager;
  7. import android.view.View.OnClickListener;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.Button;
  10. import android.widget.CheckBox;
  11. import android.widget.EditText;
  12. import android.widget.RadioButton;
  13. import android.widget.Spinner;
  14. public class MainActivity extends Activity implements OnClickListener {
  15. //1:定义id控件
  16. private EditText etusername,etpwd;
  17. private RadioButton rbM,rbW;
  18. private CheckBox cb1,cb2,cb3,cb4;
  19. private Button btnCommit,btnCancle;
  20. private Spinner spItem;
  21. String[] items = null;
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. //影藏状态栏
  26. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  27. //影藏标题栏
  28. getActionBar().hide();
  29. setContentView(R.layout.activity_main);
  30. // 2:找到id控件
  31. init();
  32. // 3:设置点击事件
  33. btnCommit.setOnClickListener(this);
  34. //准备数据
  35. //标题数据
  36. items = new String[]{"移动212","移动213","移动214","移动215"};
  37. //使用适配器来进行页面和数据的链接
  38. ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
  39. R.layout.ilte,items);
  40. spItem.setAdapter(adapter);
  41. }
  42. private void init() {
  43. etusername = (EditText) findViewById(R.id.et_username);
  44. etpwd = (EditText) findViewById(R.id.et_pwd);
  45. rbM = (RadioButton) findViewById(R.id.rd_M);
  46. rbW = (RadioButton) findViewById(R.id.rd_W);
  47. cb1 = (CheckBox) findViewById(R.id.cb_1);
  48. cb2 = (CheckBox) findViewById(R.id.cb_2);
  49. cb3 = (CheckBox) findViewById(R.id.cb_3);
  50. cb4 = (CheckBox) findViewById(R.id.cb_4);
  51. btnCommit = (Button) findViewById(R.id.btn_Commit);
  52. btnCancle = (Button) findViewById(R.id.btn_Cancle);
  53. spItem = (Spinner) findViewById(R.id.sp_Item);
  54. }
  55. @Override
  56. public void onClick(View arg0) {
  57. //4:获取用户名
  58. String userName = etusername.getText().toString();
  59. //5:获取密码
  60. String pwd = etpwd.getText().toString();
  61. //6:获取性别单选
  62. String sex = "";
  63. if(rbM.isChecked()){
  64. sex = rbM.getText().toString();
  65. }
  66. if(rbW.isChecked()){
  67. sex = rbW.getText().toString();
  68. }
  69. //7:获取爱好
  70. String fav = "";
  71. if(cb1.isChecked()){
  72. fav += cb1.getText().toString();
  73. }
  74. if(cb2.isChecked()){
  75. fav += cb2.getText().toString();
  76. }
  77. if(cb3.isChecked()){
  78. fav += cb3.getText().toString();
  79. }
  80. if(cb4.isChecked()){
  81. fav += cb4.getText().toString();
  82. }
  83. //7.2获取下拉列表选中的内容
  84. int i = spItem.getSelectedItemPosition();
  85. String spItem = items[i];
  86. //8:传值跳转
  87. Intent it = new Intent(getApplicationContext(),InfoActivity.class);
  88. it.putExtra("userName",userName);
  89. it.putExtra("pwd",pwd);
  90. it.putExtra("sex",sex);
  91. it.putExtra("fav",fav);
  92. it.putExtra("spItem",spItem);
  93. startActivity(it);
  94. }
  95. }

2.2:这里有个下拉列表的字体和背景修改

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TextView xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:textSize="20dp"
  6. android:textColor="#3fcc75" >
  7. </TextView>

 3:第二个页面和第三个页面进行连接

  1. package com.example.day5;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.view.Menu;
  6. import android.widget.TextView;
  7. import android.widget.Toast;
  8. public class InfoActivity extends Activity {
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_info);
  13. Intent it = getIntent();
  14. String userName = it.getStringExtra("userName");
  15. String pwd = it.getStringExtra("pwd");
  16. String sex = it.getStringExtra("sex");
  17. String fav = it.getStringExtra("fav");
  18. String spItem = it.getStringExtra("spItem");
  19. String str = userName + ":" + pwd + ":"+sex+":"+fav+":"+spItem;
  20. Toast.makeText(getApplicationContext(), str, 1).show();
  21. TextView tvShow = (TextView) findViewById(R.id.tv_show);
  22. tvShow.setText(str);
  23. }
  24. }

 五:运行

 

 

 六:这样就可以看到实现3个页面的跳转l

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号