TextView+Button

        TextView

1. TextView basic structure + syntax

***textView is a component used by android studio to display strings and text files. It is an area to display a piece of text on a mobile phone***

***textView is an embedded module, some syntax is common***

1. First upload the code and then introduce it one by one

<?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"
>
%上面布局是相对布局,具体介绍参考上一篇文章
    <TextView
        android:id="@+id/num_1"    %id声明
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#3399ff"
        android:layout_marginTop="10dp"
        android:text="baby"           %text命令用来书写要显示的内容
        android:textColor="#ff0066"   %字体颜色
        android:textSize="35sp"       %字体尺寸
        android:gravity="center"      %字体布局
        />

</RelativeLayout>

***As shown in the figure, TextView is similar to View, except that the former is a text setting module, and the latter is a view setting module; we write the text baby through the text function, the text color is red, the size is 35sp, and the layout is finalized through gravity central***

 ***The specific and actual effect needs to be knocked by your own hands, and the result can be referred to***

Button

1. Button basic structure + syntax

***Button is an English word, noun, verb, when used as a noun, it means "button; button, in android studio, is a button component, just like the app in your mobile phone, you can enter it with one click, this mode I will write the settings later, here we first introduce the basic grammar and organization***

1. First upload the code and then introduce them one by one

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >
%上面是系统默配置这里不再赘述

    <Button       %Button声明,里面的好多语法都是通用的
        android:id="@+id/btn_1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:text="hello"
        android:textSize="20sp"
        android:background="#ff33ff"
        android:textColor="#3399ff"
        />

</LinearLayout>
%其实Button只是声明了一个外部结构而已,内部调用的还是我们在TextView和View里面调用的函数,

 ***As shown in the figure, write a Button component in the xml file, which is only a part. If you want to see the click effect, you must declare it in the corresponding .java and have a corresponding secondary file ***

 ***Actually, Button, view, and textview are both system components, and you can even just change the name***

TextView+Button constitutes a click component

***We configure a click event below, and the secondary display file is TextView***

1. Configure Button

***Button is in the xml file corresponding to MianActivity***

 *** The picture above is the initial file style when creating a new blank document ***

 1. First, we create a new Button in activity_main.xml (just copy the code of the Button module above)

 *** The picture above is the original code, we can see l*** by opening the location of 1

  *** The position shown in 2 above is the code copied from BUtton; note: remove the comment after %; and then see 3 after running ***

2. Next, we find the location of the MianActivity.java file, and create a new java file named textview

*** Find the folder where this file is located **

*** Right click new-->activity-->empty activity, create new ** 

*** Name it textview, then click finish ** 

*** The system will automatically generate the corresponding .java file and xml file as shown in Figure 1 and 2 ** 

 *** Then copy the code in the textview above, as shown in Figure 2; **

*** So far, the content of Button and text view has been written, and finally we will call it**  

3. Configure the connection between Button and textview

1. Find the MainActivity.Java file and open it

2. According to the 1 2 3 4 shown in the figure below, write the following codes in sequence 

1: Declare the BUtton

2: Find the Button (note that btn_1 is the id of the button)

3: Set the click event

4: Set the secondary file after clicking, and start

 

 3. Last point to run

 *** The Button style is displayed first. One click **

 *** Then enter the secondary file textview ** 

 *** The above is the combined design of Button and textview, for your reference**

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_63863334/article/details/127713763