Android第3周作业

1.创建3个界面

第一个界面有3个button

第二个界面有单选按钮 学历:初中 高中 专科 本科

第三个界面有5个复选框 学过哪些课程 Java Ios Android Html  Jsp

把第二个界面设置为启动界面

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:id="@+id/r_1"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:background="#FFFFFF"
 8     tools:context=".MainActivity"
 9     android:orientation="vertical">
10 
11     <Button
12         android:id="@+id/btn_1"
13         android:layout_width="match_parent"
14         android:layout_height="wrap_content"
15         android:background="@drawable/btn_3"
16         android:textColor="#181F1F"
17         android:textSize="20sp"
18         android:layout_margin="5dp"
19         android:text="按钮1"/>
20     <Button
21         android:id="@+id/btn_3"
22         android:layout_width="match_parent"
23         android:layout_height="wrap_content"
24         android:background="@drawable/btn_3"
25         android:textColor="#181F1F"
26         android:textSize="20sp"
27         android:layout_below="@id/btn_1"
28         android:layout_margin="5dp"
29         android:text="按钮2"/>
30     <Button
31         android:id="@+id/btn_4"
32         android:layout_width="match_parent"
33         android:layout_height="wrap_content"
34         android:background="@drawable/btn_3"
35         android:textColor="#181F1F"
36         android:textSize="20sp"
37         android:layout_below="@id/btn_3"
38         android:layout_margin="5dp"
39         android:text="按钮3"/>
40 
41 </RelativeLayout>
1 <?xml version="1.0" encoding="utf-8"?>
2 <shape xmlns:android="http://schemas.android.com/apk/res/android"
3     android:shape="rectangle">
4     <stroke android:color="#0B29F0"
5             android:width="1dp"/>
6     <corners android:radius="15dp"/>
7 
8 </shape>

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/r_1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:background="#FFFFFF"
 7     android:orientation="vertical">
 8     <LinearLayout
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:orientation="vertical">
12         <TextView
13             android:layout_width="wrap_content"
14             android:layout_height="wrap_content"
15             android:text="学历:"
16             android:textSize="50dp"
17             android:height="200px"/>
18         <RadioGroup
19             android:id="@+id/RadioGroup1"
20             android:layout_width="wrap_content"
21             android:layout_height="wrap_content"
22             android:orientation="vertical">
23             <RadioButton
24                 android:id="@+id/v1"
25                 android:layout_width="wrap_content"
26                 android:layout_height="200px"
27                 android:textSize="40dp"
28                 android:text="初中"/>
29             <RadioButton
30                 android:id="@+id/v2"
31                 android:layout_width="wrap_content"
32                 android:layout_height="200px"
33                 android:textSize="40dp"
34                 android:text="高中"/>
35             <RadioButton
36                 android:id="@+id/v3"
37                 android:layout_width="wrap_content"
38                 android:layout_height="200px"
39                 android:textSize="40dp"
40                 android:text="专科"/>
41             <RadioButton
42                 android:id="@+id/v4"
43                 android:layout_width="wrap_content"
44                 android:layout_height="200px"
45                 android:textSize="40dp"
46                 android:text="本科"/>
47         </RadioGroup>
48     </LinearLayout>
49 </RelativeLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:id="@+id/r_1"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     tools:context=".Main3Activity"
 8     android:background="#FFFFFF"
 9     android:orientation="vertical">
10     <TextView
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:textSize="20sp"
14         android:text="学过哪些课程:"/>
15     <CheckBox
16         android:id="@+id/Java"
17         android:layout_width="wrap_content"
18         android:layout_height="wrap_content"
19         android:textSize="20sp"
20         android:text="Java"/>
21     <CheckBox
22         android:id="@+id/los"
23         android:layout_width="wrap_content"
24         android:layout_height="wrap_content"
25         android:textSize="20sp"
26         android:text="los"/>
27     <CheckBox
28         android:id="@+id/Android"
29         android:layout_width="wrap_content"
30         android:layout_height="wrap_content"
31         android:textSize="20sp"
32         android:text="Android"/>
33     <CheckBox
34         android:id="@+id/Html"
35         android:layout_width="wrap_content"
36         android:layout_height="wrap_content"
37         android:textSize="20sp"
38         android:text="Html"/>
39     <CheckBox
40         android:id="@+id/JSP"
41         android:layout_width="wrap_content"
42         android:layout_height="wrap_content"
43         android:textSize="20sp"
44         android:text="JSP"/>
45 </LinearLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.example.week3">
 4 
 5     <application
 6         android:allowBackup="true"
 7         android:icon="@mipmap/ic_launcher"
 8         android:label="@string/app_name"
 9         android:roundIcon="@mipmap/ic_launcher_round"
10         android:supportsRtl="true"
11         android:theme="@style/AppTheme">
12         <activity android:name=".Main3Activity"></activity>
13         <activity android:name=".Main2Activity">
14             <intent-filter>
15                 <action android:name="android.intent.action.MAIN" />
16 
17                 <category android:name="android.intent.category.LAUNCHER" />
18             </intent-filter>
19         </activity>
20         <activity android:name=".MainActivity"></activity>
21     </application>
22 
23 </manifest>

2.在界面1上设置按钮点击事件

按钮1用onclick方式

按钮2和按钮3用监听方式

点击后用Toast弹出 按钮xxx被点击

 1 package com.example.week3;
 2 
 3 import androidx.appcompat.app.AppCompatActivity;
 4 import android.os.Bundle;
 5 import android.view.View;
 6 import android.widget.Button;
 7 import android.widget.Toast;
 8 public class MainActivity extends AppCompatActivity {
 9     Button v1;
10     @Override
11     protected void onCreate(Bundle savedInstanceState) {
12         super.onCreate(savedInstanceState);
13         setContentView(R.layout.activity_main);
14         v1=findViewById(R.id.btn_1);
15         v1.setOnClickListener(new View.OnClickListener() {
16             @Override
17             public void onClick(View view) {
18                 Toast.makeText(MainActivity.this,"按钮1被点击",Toast.LENGTH_LONG).show();
19             }
20         });
21     }
22     public void showToast(View view){
23         Toast.makeText(this,"按钮2被点击",Toast.LENGTH_LONG).show();
24     }
25     public void showToast1(View view){
26         Toast.makeText(this,"按钮3被点击",Toast.LENGTH_LONG).show();
27     }
28 }

 3.设计布局界面

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <RelativeLayout 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:id="@+id/r_1"
  6     android:layout_width="match_parent"
  7     android:layout_height="match_parent"
  8     android:background="#FFFFFF"
  9     tools:context=".MainActivity"
 10     android:orientation="vertical">
 11     <ImageButton
 12         android:id="@+id/b1"
 13         android:layout_width="wrap_content"
 14         android:layout_height="wrap_content"
 15         android:layout_marginTop="80dp"
 16         android:background="@drawable/tb" />
 17     <EditText
 18         android:id="@+id/b2"
 19         android:layout_width="match_parent"
 20         android:layout_height="80dp"
 21         android:layout_below="@id/b1"
 22         android:layout_marginTop="-64dp"
 23         android:gravity="center"
 24         android:hint="请输入手机号/邮箱" />
 25     <EditText
 26         android:id="@+id/b3"
 27         android:layout_width="match_parent"
 28         android:layout_height="80dp"
 29         android:hint="请输入密码"
 30         android:layout_below="@id/b2"
 31         android:gravity="center"
 32         android:drawableRight="@drawable/ck"/>
 33     <Button
 34         android:id="@+id/b4"
 35         android:layout_width="350dp"
 36         android:layout_height="60dp"
 37         android:layout_below="@id/b3"
 38         android:layout_centerHorizontal="true"
 39         android:text="登录"
 40         android:background="@drawable/btn_2"
 41         android:textColor="#FFFFFF"/>
 42     <Button
 43         android:id="@+id/b5"
 44         android:layout_width="350dp"
 45         android:layout_height="60dp"
 46         android:layout_below="@id/b4"
 47         android:layout_centerHorizontal="true"
 48         android:text="不注册,跳过登录"
 49         android:background="@drawable/btn_1"
 50         android:textColor="#FFFFFF"
 51         android:layout_marginTop="20dp"/>
 52     <TextView
 53         android:id="@+id/b6"
 54         android:layout_width="wrap_content"
 55         android:layout_height="wrap_content"
 56         android:text="注册账号"
 57         android:layout_below="@id/b5"
 58         android:layout_alignLeft="@id/b5"/>
 59     <TextView
 60         android:id="@+id/b7"
 61         android:layout_width="wrap_content"
 62         android:layout_height="wrap_content"
 63         android:text="忘记密码"
 64         android:layout_below="@id/b5"
 65         android:layout_alignRight="@id/b5"/>
 66     <ImageView
 67         android:id="@+id/b8"
 68         android:layout_width="wrap_content"
 69         android:layout_height="wrap_content"
 70         android:background="@drawable/wx"
 71         android:layout_below="@id/b7"
 72         android:layout_marginLeft="100dp"
 73         android:layout_marginTop="20dp"/>
 74     <ImageView
 75         android:id="@+id/b9"
 76         android:layout_width="wrap_content"
 77         android:layout_height="wrap_content"
 78         android:background="@drawable/ios"
 79         android:layout_below="@id/b7"
 80         android:layout_centerHorizontal="true"
 81         android:layout_marginTop="20dp"/>
 82     <ImageView
 83         android:id="@+id/b10"
 84         android:layout_width="wrap_content"
 85         android:layout_height="wrap_content"
 86         android:layout_below="@id/b7"
 87         android:layout_marginLeft="56dp"
 88         android:layout_marginTop="19dp"
 89         android:layout_toRightOf="@id/b9"
 90         android:background="@drawable/qq1" />
 91     <CheckBox
 92         android:id="@+id/z1"
 93         android:layout_width="wrap_content"
 94         android:layout_height="wrap_content"
 95         android:layout_marginLeft="80dp"
 96         android:layout_below="@id/b8"
 97         android:layout_marginTop="20dp"/>
 98     <TextView
 99         android:id="@+id/z2"
100         android:layout_width="wrap_content"
101         android:layout_height="wrap_content"
102         android:layout_below="@id/b8"
103         android:layout_marginLeft="0dp"
104         android:layout_marginTop="27dp"
105         android:layout_toRightOf="@id/z1"
106         android:text="已阅读并同意" />
107     <TextView
108         android:id="@+id/z3"
109         android:layout_width="wrap_content"
110         android:layout_height="wrap_content"
111         android:layout_below="@id/b8"
112         android:layout_marginLeft="0dp"
113         android:layout_marginTop="27dp"
114         android:layout_toRightOf="@id/z2"
115         android:text="《用户协议》"
116         android:textColor="#FA5050"/>
117     <TextView
118         android:id="@+id/z4"
119         android:layout_width="wrap_content"
120         android:layout_height="wrap_content"
121         android:layout_below="@id/b8"
122         android:layout_marginLeft="0dp"
123         android:layout_marginTop="27dp"
124         android:layout_toRightOf="@id/z3"
125         android:text="和" />
126     <TextView
127         android:id="@+id/z5"
128         android:layout_width="wrap_content"
129         android:layout_height="wrap_content"
130         android:layout_below="@id/b8"
131         android:layout_marginLeft="0dp"
132         android:layout_marginTop="27dp"
133         android:layout_toRightOf="@id/z4"
134         android:text="《隐私政策》"
135         android:textColor="#FA5050"/>
136 </RelativeLayout>

 

posted @ 2021-09-04 17:47  宇文92  阅读(23)  评论(0编辑  收藏  举报