android studio 创建按钮项目

1)、新建一个empty activity项目,切换到project视图:

2)、修改app\src\main\res\layout\activity_main.xml文件,修改后如下:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello everyone!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/button"
        app:layout_constraintStart_toStartOf="@+id/button"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="开灯"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

3)、点击运行,运行效果如下:

相关推荐
2501_9327502639 分钟前
Android 自定义 View 入门
android
事圆则缓3 小时前
Android 开启线程的几种方式:Thread、线程池、HandlerThread 与协程
android
oooost4 小时前
Jupyter Notebook 常用快捷键速查
ide·python·jupyter
yqj23412 小时前
ESP32-S3中小智项目优化内容
ide·macos·xcode
半摆烂日常17 小时前
低代码平台API对接实践:接口鉴权与数据同步的完整实现
android·低代码·rxjava
事圆则缓18 小时前
volatile 使用场景全解析:它能保证什么,又解决不了什么
android
蒲公英内测分发19 小时前
智能投影仪参加海外展会,未上架的 Android 配套 App 怎么让客户限时试用?
android
ii_best19 小时前
按键精灵手机端开发安卓版实战:手写一个可最小化、可拖动的「运行日志悬浮窗」(附完整 源码 + 踩坑记录)
android·ios·智能手机·自动化·ai编程·按键精灵
终端安全笔记19 小时前
安卓做 MDM 管控,先分清三种注册入口
android·安全·智能手机
阿斌.com20 小时前
Visual Studio 2026安装全攻略
ide·visual studio