Android第二次作業


1.創建3個界面

第一個界面有3個button

第二個界面有單選按鈕 學歷:初中 高中 專科 本科

第三個界面有5個復選框  學過哪些課程

Java

Ios

Android

Html

Jsp

把第二個界面設置為啟動界面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo1Activity" android:orientation="vertical"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕1" android:onClick="click1"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕2"/> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕3"/> </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo2Activity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你的學歷是什么?" android:textColor="#0A0A0A"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="初中" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="高中" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="專科" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="本科"/> </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo3Activity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你學過哪些課程" android:textColor="#000000"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="JAVA"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="IOS"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ANDROID"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HTML"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="JSP"/> </LinearLayout>

2.在界面1上設置按鈕點擊事件

按鈕1用onclick方式

按鈕2和按鈕3用監聽方式

點擊后用Toast彈出 按鈕xxx被點擊。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo1Activity" android:orientation="vertical"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕1" android:onClick="click1"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕2"/> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕3"/> </LinearLayout>
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Demo1Activity extends AppCompatActivity { private Button btn2; private Button btn3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo1); btn2=findViewById(R.id.button2); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(Demo1Activity.this, "按鈕2被點擊", Toast.LENGTH_SHORT).show(); } }); btn3=findViewById(R.id.button3); btn3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(Demo1Activity.this, "按鈕3被點擊", Toast.LENGTH_SHORT).show(); } }); } public void click1(View view){ Toast.makeText(this, "按鈕1被點擊", Toast.LENGTH_SHORT).show(); } }

 

3.設計布局界面(詳見QQ群)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Main2Activity" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/xiaobiaodayin" android:layout_gravity="center" android:layout_marginTop="100dp"/> <EditText android:layout_width="match_parent" android:layout_height="80dp" android:hint="請輸入手機號/郵箱" android:layout_marginTop="50dp" android:gravity="center" /> <EditText android:layout_width="match_parent" android:layout_height="80dp" android:hint="請輸入密碼" android:gravity="center" android:drawableRight="@drawable/yanjingbi" android:drawablePadding="10dp" android:layout_marginTop="10dp"/> <Button android:layout_width="400dp" android:layout_height="50dp" android:text="登錄" android:textColor="#FFFFFF" android:gravity="center" android:layout_gravity="center" android:layout_marginTop="30dp" android:background="@drawable/btn_2" /> <Button android:layout_width="400dp" android:layout_height="50dp" android:text="不注冊,跳過登錄" android:textColor="#FFFFFF" android:gravity="center" android:layout_gravity="center" android:background="@drawable/btn_3" android:layout_marginTop="10dp" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注冊賬號" android:layout_margin="10dp" android:layout_alignParentLeft="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注冊賬號" android:layout_margin="10dp" android:layout_alignParentRight="true" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/weixin" android:layout_alignParentLeft="true" android:layout_marginLeft="100dp"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/pingguo" android:layout_centerInParent="true"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/qq" android:layout_alignParentRight="true" android:layout_marginRight="100dp"/> </RelativeLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <CheckBox android:id="@+id/z1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" /> <TextView android:id="@+id/z2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="已閱讀並同意" android:layout_toRightOf="@+id/z1" android:padding="5dp"/> <TextView android:id="@+id/z3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="《用戶協議》" android:textColor="#FA0606" android:layout_toRightOf="@id/z2" android:padding="5dp"/> <TextView android:id="@+id/z4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="和" android:layout_toRightOf="@id/z3" android:padding="5dp"/> <TextView android:id="@+id/z5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="《隱私政策》" android:textColor="#FA0606" android:layout_toRightOf="@id/z4" android:padding="5dp"/> </RelativeLayout> </LinearLayout>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM