Android第3周作业

<?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=".MainActivity"
    android:orientation="vertical">
    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮1"
        android:background="#B31C6A"
        android:textColor="#000000"
        android:layout_margin="10dp"/>
    <Button
        android:id="@+id/btn_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮2"
        android:background="#6EB31C"
        android:textColor="#000000"
        android:layout_margin="10dp"/>
    <Button
        android:id="@+id/btn_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮3"

        android:background="#1D4488"
        android:textColor="#000000"
        android:layout_margin="10dp"/>

</LinearLayout>

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="你的学历是"
     android:textSize="35sp"
     android:layout_margin="10dp"/>
   <RadioGroup
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"></RadioGroup>
    <RadioButton
        android:id="@+id/rb_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:text="初中"
        android:textSize="30dp"
        android:textColor="#2196F3"/>
    <RadioButton
        android:id="@+id/rb_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:layout_below="@id/rb_1"
        android:text="高中"
        android:textSize="30dp"
        android:textColor="#2196F3"/>

    <RadioButton
        android:id="@+id/rb_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:layout_below="@id/rb_2"
        android:text="专科"
        android:textSize="30dp"
        android:textColor="#2196F3"/>
    <RadioButton
        android:id="@+id/rb_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:layout_below="@id/rb_3"
        android:text="本科"
        android:textSize="30dp"
        android:textColor="#2196F3"/>

</RelativeLayout>

 

 

<?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"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:text="你都学过哪些课程?"
        android:layout_margin="10dp"
        android:textSize="15pt"
        android:textColor="#604D81"/>
    <CheckBox
        android:id="@+id/cb_1"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:text="Java"
        android:textSize="10pt"
        android:layout_margin="10dp"/>
    <CheckBox
        android:id="@+id/cb_2"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:text="Ios"
        android:textSize="10pt"
        android:layout_margin="10dp"/>
    <CheckBox
        android:id="@+id/cb_3"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:text="Android"
        android:textSize="10pt"
        android:layout_margin="10dp"/>
    <CheckBox
        android:id="@+id/cb_4"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:text="Html"
        android:textSize="10pt"
        android:layout_margin="10dp"/>
    <CheckBox
        android:id="@+id/cb_5"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:text="Jsp"
        android:textSize="10pt"
        android:layout_margin="10dp"/>
 
</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"
    android:orientation="vertical">
    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮1"
        android:layout_marginBottom="5dp"
        android:onClick="click1"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        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 ToastActivity extends AppCompatActivity {
 
    private Button btn3;
    private Button btn2;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);
        btn3=findViewById(R.id.button3);
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(ToastActivity.this,"按钮3被点击",Toast.LENGTH_LONG).show();
            }
        });
 
        btn2=findViewById(R.id.button2);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(ToastActivity.this,"按钮2被点击",Toast.LENGTH_SHORT).show();
            }
        });
    }
 
    public void click1(View view){
        Toast.makeText(this,"按钮1被点击",Toast.LENGTH_LONG).show();
    }
}

 

posted @ 2021-10-07 14:35  藜莂  阅读(12)  评论(0编辑  收藏  举报