Android IoT开发实战 | 07 - 常用控件的使用

262 阅读1分钟

本系列IoT App开发笔记系b站视频教程学习笔记,视频地址:

1. TextView

使用示例:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/test_textView"
    android:text="TextView"
    android:gravity="center"
    android:textSize="24sp"
   	android:textColor="@color/colorPrimary"
    />

2. Button

2.1. 布局

使用示例:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/test_button"
    android:text="button"
    android:textAllCaps="false"
    android:layout_gravity="center"
    />

2.2. 监听器

在活动文件的OnCreate()函数中注册:

Button test_button = (Button)findViewById(R.id.test_button);

//匿名方式注册监听器
test_button.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View view) {
        //按钮按下后需要执行的代码
    }
});

3. EditText

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/test_edittext"
    android:hint="please enter here"
    android:maxLines="1"
    />

4. ImageView

使用示例:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/test_imageview"
    android:src="@drawable/ic_launcher_foreground"
    />


接收更多精彩文章及资源推送,欢迎订阅我的微信公众号:『mculover666』。