Android第三周作业
1.创建3个界面
第一个界面有3个button
第二个界面有单选按钮 学历:初中 高中 专科 本科
第三个界面有5个复选框 学过哪些课程
Java
Ios
Android
Html
Jsp
把第二个界面设置为启动界面
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 tools:context=".Demo1Activity" 8 android:orientation="vertical"> 9 <Button 10 android:id="@+id/button1" 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 android:text="按钮1" 14 android:onClick="click1"/> 15 16 <Button 17 android:id="@+id/button2" 18 android:layout_width="match_parent" 19 android:layout_height="wrap_content" 20 android:text="按钮2"/> 21 22 <Button 23 android:id="@+id/button3" 24 android:layout_width="match_parent" 25 android:layout_height="wrap_content" 26 android:text="按钮3"/> 27 </LinearLayout>

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 tools:context=".Demo2Activity" 8 android:orientation="vertical"> 9 <TextView 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:text="你的学历是什么?" 13 android:textColor="#0A0A0A"/> 14 15 <RadioButton 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" 18 android:text="初中" 19 /> 20 <RadioButton 21 android:layout_width="wrap_content" 22 android:layout_height="wrap_content" 23 android:text="高中" 24 /> 25 <RadioButton 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:text="专科" 29 /> 30 <RadioButton 31 android:layout_width="wrap_content" 32 android:layout_height="wrap_content" 33 android:text="本科"/> 34 35 36 </LinearLayout>

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 tools:context=".Demo3Activity" 8 android:orientation="vertical"> 9 10 <TextView 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:text="你学过哪些课程" 14 android:textColor="#000000"/> 15 <CheckBox 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" 18 android:text="JAVA"/> 19 <CheckBox 20 android:layout_width="wrap_content" 21 android:layout_height="wrap_content" 22 android:text="IOS"/> 23 <CheckBox 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:text="ANDROID"/> 27 <CheckBox 28 android:layout_width="wrap_content" 29 android:layout_height="wrap_content" 30 android:text="HTML"/> 31 <CheckBox 32 android:layout_width="wrap_content" 33 android:layout_height="wrap_content" 34 android:text="JSP"/> 35 </LinearLayout>

2.在界面1上设置按钮点击事件
按钮1用onclick方式
按钮2和按钮3用监听方式
点击后用Toast弹出 按钮xxx被点击。
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical"> 6 <Button 7 android:id="@+id/button1" 8 android:layout_width="match_parent" 9 android:layout_height="wrap_content" 10 android:background="@drawable/btn_1" 11 android:textColor="#00FFEE" 12 android:layout_margin="15dp" 13 android:text="按钮一" 14 android:onClick="click1"></Button> 15 <Button 16 android:id="@+id/botton2" 17 android:layout_width="match_parent" 18 android:layout_height="wrap_content" 19 android:background="@drawable/btn_1" 20 android:textColor="#00FFEE" 21 android:layout_below="@id/button1" 22 android:layout_margin="15dp" 23 android:text="按钮二"></Button> 24 <Button 25 android:id="@+id/botton3" 26 android:layout_width="match_parent" 27 android:layout_height="wrap_content" 28 android:background="@drawable/btn_1" 29 android:textColor="#00FFEE" 30 android:layout_below="@id/botton2" 31 android:layout_margin="15dp" 32 android:text="按钮三"></Button> 33 </LinearLayout>
package itcast.cn; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class ToastActivity extends AppCompatActivity { private Button btn1; private Button btn2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_toast); btn1=findViewById(R.id.botton2); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(ToastActivity.this,"按钮二被点击",Toast.LENGTH_LONG).show(); } }); btn2=findViewById(R.id.botton3); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(ToastActivity.this,"按钮三被点击",Toast.LENGTH_LONG).show(); } }); } public void click1(View view){ Toast.makeText(this,"按钮一被点击",Toast.LENGTH_LONG).show(); } }

3.设计布局界面(详见QQ群)
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical"> 6 7 <ImageButton 8 android:id="@+id/v_1" 9 android:layout_width="300dp" 10 android:layout_height="150dp" 11 android:layout_gravity="center_horizontal" 12 android:layout_centerInParent="true" 13 android:background="#FFFFFF" 14 android:src="@drawable/image"></ImageButton> 15 16 <EditText 17 android:id="@+id/v_2" 18 android:layout_width="match_parent" 19 android:layout_height="80dp" 20 android:hint=" 请输入手机号/邮箱" 21 android:maxLines="2" 22 android:textColor="#000000" 23 android:textSize="20sp"></EditText> 24 25 <EditText 26 android:id="@+id/v_3" 27 android:layout_width="match_parent" 28 android:layout_height="60dp" 29 android:hint=" 请输入密码" 30 android:textColor="#000000" 31 android:textSize="20sp" 32 android:drawableRight="@drawable/see"></EditText> 33 34 <Button 35 android:id="@+id/btn_1" 36 android:layout_width="300dp" 37 android:layout_height="60dp" 38 android:layout_below="@id/v_3" 39 android:background="@drawable/btn_1" 40 android:text="登录" 41 android:layout_gravity="center" 42 android:layout_marginTop="30dp" 43 android:textColor="#FFFFFF"></Button> 44 45 <Button 46 android:id="@+id/btn_3" 47 android:layout_width="300dp" 48 android:layout_height="60dp" 49 android:background="@drawable/btn_3" 50 android:layout_gravity="center" 51 android:textColor="#FFFFFF" 52 android:layout_below="@id/v_3" 53 android:layout_marginTop="20dp" 54 android:text="不注册,跳过登录"></Button> 55 56 <TextView 57 android:id="@+id/v_4" 58 android:layout_width="100dp" 59 android:layout_height="50dp" 60 android:text="注册账号" 61 android:layout_gravity="left" 62 android:layout_marginTop="15dp" 63 android:textSize="20sp"> 64 </TextView> 65 <TextView 66 android:id="@+id/v_5" 67 android:layout_width="100dp" 68 android:layout_height="50dp" 69 android:layout_marginTop="-50dp" 70 android:text="忘记密码" 71 android:layout_gravity="right" 72 android:textSize="20dp"> 73 74 </TextView> 75 <ImageButton 76 android:layout_width="100dp" 77 android:layout_height="100dp" 78 android:src="@drawable/we2" 79 android:background="#FFFFFF" 80 android:layout_marginLeft="50dp"></ImageButton> 81 82 <ImageButton 83 android:layout_width="100dp" 84 android:layout_height="100dp" 85 android:layout_marginLeft="10dp" 86 android:background="#FFFFFF" 87 android:layout_gravity="center" 88 android:layout_marginTop="-100dp" 89 android:src="@drawable/apple"></ImageButton> 90 91 <ImageButton 92 android:layout_width="100dp" 93 android:layout_height="100dp" 94 android:src="@drawable/qq" 95 android:background="#FFFFFF" 96 android:layout_gravity="right" 97 android:layout_marginRight="30dp" 98 android:layout_marginTop="-103dp"></ImageButton> 99 100 <CheckBox 101 android:layout_width="wrap_content" 102 android:layout_height="wrap_content" 103 android:layout_marginLeft="60dp" 104 android:layout_marginTop="0dp" 105 android:text="已阅读并同意 和" 106 android:textColor="#000000"></CheckBox> 107 108 <TextView 109 android:layout_width="90dp" 110 android:layout_height="20dp" 111 android:text="《用户协议》" 112 android:textColor="#FF0000" 113 android:layout_marginLeft="170dp" 114 android:layout_marginTop="-25dp"></TextView> 115 <TextView 116 android:layout_width="90dp" 117 android:layout_height="20dp" 118 android:text="《隐私政策》" 119 android:textColor="#FF0000" 120 android:layout_marginLeft="260dp" 121 android:layout_marginTop="-21dp"></TextView> 122 </LinearLayout>

浙公网安备 33010602011771号