Big task1 - Experiment task1

Writing an App,the root layout is a vertical LinearLayout with 4 horizontal LinearLayouts and 3 TextViews. The App’s name should contain your name message (initials of your name). 
The 1st horizontal LinearLayout, within 1 TextView and 1 EditText, the width space is 1:3, the text in the TextView is right align. The EditText has the text for hint. 
The 2nd horizontal LinearLayout, within 1 Button and 1 TextView. The TextView shows the message of the EditText when users click the button 
The 3rd horizontal LinearLayout, within 3 RadioButtons (equal width). 
The 4th horizontal LinearLayout, within 3 Checkboxes (equal width). 
The 1st TextView below the last horizontal LinearLayout shows the checked RadioButtons. The text color is red. 
The 2nd TextView shows the checked Checkboxes. The text color is blue. 
The 3rd TextView shows your name and student number. The text font size is 14sp.

翻译:

写一个应用程序,根布局是一个垂直线性布局,有4个水平线性布局和3个文本视图。应用程序的名称应该包含您的姓名信息(您姓名的首字母)。 第一个水平线性布局,在1个文本视图和1个编辑文本内,宽度间隔为1:3,文本视图中的文本右对齐。编辑文本包含提示文本。 第二个水平线性布局,在1个按钮和1个文本视图内。当用户点击按钮时,文本视图显示编辑文本的信息 第三个水平线形布局,在3个单选按钮内(等宽)。 第四个水平线形布局,在3个复选框内(等宽)。 最后一个水平线条布局下方的第一个文本视图显示选中的单选按钮。文本颜色为红色。 第二个文本视图显示选中的复选框。文本颜色为蓝色。 第三个文本视图显示您的姓名和学生编号。文本字体大小为14sp。

首先编辑color.xml文件,其中colorPrimaryDark是原有的蓝色,还添加红色 #D24D57

<?xml version="1.0" encoding="utf-8"?>    #6200EE    #3700B3         //蓝色    #03DAC5    #D24D57

之后再来根据要求编辑我们my_main.xml文件

<?xml version="1.0" encoding="utf-8"?>                                    

根据要求编写MainActivity.java函数

package com.example.lrz_exp1;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class MainActivity extends AppCompatActivity {    CheckBox cb1,cb2,cb3;    TextView tv1,tv2;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.my_main);        final EditText et=findViewById(R.id.et);        Button bt=findViewById(R.id.bt1);        final TextView tv5=findViewById(R.id.tv5);        bt.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                String s1=et.getText().toString();                tv5.setText(s1);            }        });        RadioGroup rg=findViewById(R.id.rg1);        tv1=findViewById(R.id.tv1);        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(RadioGroup group, int checkedId) {                RadioButton rb=findViewById(checkedId);                tv1.setText(rb.getText());            }        });        cb1=findViewById(R.id.cb1);        cb2=findViewById(R.id.cb2);        cb3=findViewById(R.id.cb3);        tv2=findViewById(R.id.tv2);        cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                updateCheckBox();            }        });        cb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                updateCheckBox();            }        });        cb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                updateCheckBox();            }        });    }    private void updateCheckBox(){        String s2="";        if(cb1.isChecked()){            s2+=cb1.getText()+" ";        }        if(cb2.isChecked()){            s2+=cb2.getText()+" ";        }        if(cb3.isChecked()){            s2+=cb3.getText()+" ";        }        tv2.setText(s2);    }}

学习笔记,水平有限,若有问题欢迎探讨^.^

更多相关文章

  1. Android:自动完成文本框
  2. 阅读《Android 从入门到精通》(29)——四大布局
  3. android 窗口如何靠左和靠右边框布局
  4. android 自定义View 在布局文件中写法
  5. 使用命令建立简单的布局
  6. Android学习笔记6——基本布局
  7. AndroidTextView的跑马灯效果,解决复杂布局不能获取焦点的问题

随机推荐

  1. Android开发新手第一要素
  2. android 时间1
  3. Android如何快速打开系统软键盘和关闭系
  4. AspectJ是否仍可用于Android? 第2部分
  5. 《android的SQLite与文件下载》
  6. Android下图形系统
  7. android studio 使用的一些注意,一些报错
  8. android 自定义圆环
  9. 编译Linaro的Android内核有感
  10. android studio解决warning: Ignoring In