第3天~调查表

2021/01/15再用https://developer.android.com/studio
的最新版本 再写一次~

https://ithelp.ithome.com.tw/upload/images/20220115/20119035izKEH8k3gY.png

margin边界
padding内距

gravity 对齐-置中


text

textview 只能看不能输入(结帐结果)
plain text 输入框(文字+数字)
password(Numeric)输入框(数字)


要有绑定才不会显示红色
https://ithelp.ithome.com.tw/upload/images/20220117/20119035llsj1wDC6o.png


Layouts容器-LinerLayout(horizonal)
https://ithelp.ithome.com.tw/upload/images/20220117/20119035yz7QIuGhvR.png

layout_wight是比例:按两个按钮是1:1

https://ithelp.ithome.com.tw/upload/images/20220117/20119035jIdeLjFMAy.png


button的内距-layout_margin
https://ithelp.ithome.com.tw/upload/images/20220117/20119035QIriiiLK7M.png
比例10dp
https://ithelp.ithome.com.tw/upload/images/20220117/2011903565t4Kj6fXl.png


/images/emoticon/emoticon08.gif

让按钮动起来的2种办法:(要滚瓜烂熟)
1.(xml)对按钮绑定属性onClick
2.(java)找"No"设定侦听器


SOP:

id就是变数

1-改显示id为show1
https://ithelp.ithome.com.tw/upload/images/20220117/201190357tCsm9srh9.png

2-改显示id为show2

https://ithelp.ithome.com.tw/upload/images/20220117/201190354JjRjrybMF.png

3-button找到onClick然後里面也是写onClick
https://ithelp.ithome.com.tw/upload/images/20220117/20119035BmdhXhnFrL.png

https://ithelp.ithome.com.tw/upload/images/20220117/20119035Wk0ELSUcJU.png

4-到XML档-灯点-Create 'onClick(View)' in 'MainActivity'
https://ithelp.ithome.com.tw/upload/images/20220117/201190352SaiIcuWGd.png

5-点了会跳到.java档

https://ithelp.ithome.com.tw/upload/images/20220117/20119035rlcozlQtWN.png

alt+enter 也可以出现灯泡-灯点-Create 'onClick(View)' in 'MainActivity'

package com.huang.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClick(View view) {
    }
}

就不会有反红问题
因为有加入..这里就是绑好的按纽:

public void onClick(View view) {
    }

6- java档

宣告元件变数

https://ithelp.ithome.com.tw/upload/images/20220117/20119035HSrys5TRmw.png

按alt+enter选 import class

https://ithelp.ithome.com.tw/upload/images/20220117/20119035ZS7BwWij8z.png

https://ithelp.ithome.com.tw/upload/images/20220117/2011903543wzRqxbir.png


7-变数宣告

//初始化元件
        show1 = findViewById(R.id.show1);
        show2 = findViewById(R.id.show2);


8-定义按钮按下去会显示

//按钮1绑定onClick属性
    public void onClick(View view) {
        show1.setText("搞定~~~");
    }

9-OK按钮会动

https://ithelp.ithome.com.tw/upload/images/20220118/20119035zKfDG4bC74.png

package com.huang.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    //宣告元件变数
    TextView show1,show2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //初始化元件
        show1 = findViewById(R.id.show1);
        show2 = findViewById(R.id.show2);

    }
    //按钮1绑定onClick属性
    public void onClick(View view) {
        show1.setText("搞定~~~");
    }
}


10-NO按键用java档操作变数名称button
https://ithelp.ithome.com.tw/upload/images/20220118/20119035LVGbNQbNiD.png

package com.huang.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    //宣告元件变数
    TextView show1,show2;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //初始化元件
        show1 = findViewById(R.id.show1);
        show2 = findViewById(R.id.show2);
        button =findViewById(R.id.button);

    }
    //按钮1绑定onClick属性
    public void onClick(View view) {
        show1.setText("搞定~~~");
    }
}

11-加增听器
https://ithelp.ithome.com.tw/upload/images/20220118/20119035BGzCRVZCbT.png


12-加增听器-要用选的
https://ithelp.ithome.com.tw/upload/images/20220118/20119035bIC2TJuYAV.png

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                
            }

https://ithelp.ithome.com.tw/upload/images/20220118/201190358r2gcWchiw.png


13-增加按钮动作
https://ithelp.ithome.com.tw/upload/images/20220118/201190357xlUE7O6rJ.png

package com.huang.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    //宣告元件变数
    TextView show1,show2;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //初始化元件
        show1 = findViewById(R.id.show1);
        show2 = findViewById(R.id.show2);
        button =findViewById(R.id.button);
        //在按钮上加侦听器
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show2.setText("放假啦~~~");

            }
        });

    }
    //按钮1绑定onClick属性
    public void onClick(View view) {
        show1.setText("搞定~~~");
    }
}

https://ithelp.ithome.com.tw/upload/images/20220118/20119035TqgpAb7Pj3.png


/images/emoticon/emoticon06.gif

package com.huang.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    //宣告元件变数
    TextView show1,show2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClick(View view) {
    }
}

7-


在design上面看到的黄色!还可以运行..红色!不行代表错误

这次之前旧的版本写出调查表
https://ithelp.ithome.com.tw/upload/images/20211014/20119035brkMSFxo96.png

https://ithelp.ithome.com.tw/upload/images/20211023/201190358OUlXTqv6S.png

id是被定义属性
https://ithelp.ithome.com.tw/upload/images/20211023/20119035wGSYDlyF6Y.png
wrap_content=内容多大就占多大
我们很常在拖拉完物件之後都会看到旁边有一个小的黄色惊叹号,为什麽会有这个惊叹号?该怎麽消掉呢?
可以参考这篇https://www.ruyut.com/2018/12/android-studio-String.html
这个黄色惊叹号代表你的字串没有设定在@String资源中

觉得最重要的就是字要变大
https://ithelp.ithome.com.tw/upload/images/20211023/20119035cqkz820op1.png
觉得最重要的就是颜色
https://ithelp.ithome.com.tw/upload/images/20211025/20119035MjU8UeBIfC.png

textcolor就是颜色的部分
https://ithelp.ithome.com.tw/upload/images/20211025/20119035vn1YnVlG7r.png

再来是边界padding分别显示的是上/下/左/右
https://ithelp.ithome.com.tw/upload/images/20211025/20119035wnxpIktlZe.png

来真的写程序码:
/images/emoticon/emoticon01.gif

由上到下~

https://ithelp.ithome.com.tw/upload/images/20211114/20119035l2qibABOpQ.png

放入可以打字的文字是选-Plain Text
推荐一个旧版的教学网址..可是不是中文QQ-https://www.youtube.com/watch?v=V0AETAjxqLI

https://ithelp.ithome.com.tw/upload/images/20211114/20119035RJ0gDuwgQT.png

id命名一下~input

https://ithelp.ithome.com.tw/upload/images/20211115/201190352UU7UffLPv.png

增加按钮
https://ithelp.ithome.com.tw/upload/images/20211115/20119035rx0vDR28Z9.png

增加swith -像是一个开关

可以参考连结-https://www.runoob.com/w3cnote/android-tutorial-togglebutton-switch.html

要确认四边至少要有一边有绑-不然就会像模拟器这样跑掉
https://ithelp.ithome.com.tw/upload/images/20211115/20119035Crvtr8zVF3.png

结果调一调反而是input不好绑定0.0
https://ithelp.ithome.com.tw/upload/images/20211115/20119035sc6amCDJRs.png
後来发现他是写框太小..然後就解决所有反红
https://ithelp.ithome.com.tw/upload/images/20211115/20119035wrpWBa5KAq.png

再来加入button-没有绑定ID

https://ithelp.ithome.com.tw/upload/images/20211115/201190355aDHu9SPix.png

来写程序码:
https://ithelp.ithome.com.tw/upload/images/20211115/20119035BWKegqhNUQ.png

package com.huang.myapplication10;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClick(View View){

    }
}

再来把按键内的程序码写入:

package com.huang.myapplication10;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

    EditText input;
    ToggleButton toggleButton;
    Switch switch1;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        input=findViewById(R.id.input);
        toggleButton=findViewById(R.id.toggleButton);
        switch1=findViewById(R.id.switch1);


        toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if(isChecked){
                    Toast.makeText(MainActivity.this,"OK",Toast.LENGTH_SHORT).show();
                }
                else {Toast.makeText(MainActivity.this,"NO",Toast.LENGTH_SHORT).show();
                }
            }
        });

        switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    Toast.makeText(MainActivity.this,"OK",Toast.LENGTH_SHORT).show();
                }
                else {Toast.makeText(MainActivity.this,"NO",Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

    public void onClick(View View){

    }
}

https://ithelp.ithome.com.tw/upload/images/20211115/20119035cqeAJphGfZ.png


package name 不要有example不然会不能上架
https://ithelp.ithome.com.tw/upload/images/20220115/20119035ZBytzFbS4L.png

要求手机最低的版本要26以上.80几%的人可以用

要把环境设好--才不会做的很痛苦QQ
https://ithelp.ithome.com.tw/upload/images/20220115/20119035qGAHh7fZOP.png

模拟器不能编辑:
在app上按右键-Open Module Settings
--Dependenceies--app--把1.4.0--改成1.3.1


配合滚轮V
https://ithelp.ithome.com.tw/upload/images/20220115/20119035wWcUrxIVid.png


<<:  Day 17 读 Go Concurrency Patterns - Rob Pike IV

>>:  网路常常不稳的天涯若比邻

Day 17 「提枪上阵」在测试保护下重构出 State 设计模式

报告班长,图片截自网路 大家有听过「报告班长」吗?这部 1987 年的电影,当年推出後一炮而红,带...

TailwindCSS 从零开始 - 手机到桌上萤幕,所有的元素都能自适应

跟 Bootstrap 一样也是手机优先的响应式断点设计,官方文件也提供尺寸对照: 让前端在开发轻...

(Day30)第三方套件---图表套件Charts(下)

这篇会介绍图表套件Charts的功能 graphView.leftAxis.enabled = fa...

找资安工作,怎麽找?要学甚麽?该何去何从?

今天刚好进入铁人赛的一半了, 累,真滴累。虽然单纯看文章,是看不出甚麽端倪, 内容都不是很多,可是都...

随身开机碟 lubuntu 启用 fcitx 呒虾米输入法的步骤

看到了 在 Lubuntu 21.04 安装 fcitx 的呒虾米表格档 所分享的做法,也是我常会用...