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)、点击运行,运行效果如下:

相关推荐
时光追逐者3 小时前
Visual Studio 2026 现已正式发布,更快、更智能!
ide·c#·.net·visual studio
安卓理事人3 小时前
安卓LinkedBlockingQueue消息队列
android
万能的小裴同学5 小时前
Android M3U8视频播放器
android·音视频
q***57745 小时前
MySql的慢查询(慢日志)
android·mysql·adb
JavaNoober5 小时前
Android 前台服务 "Bad Notification" 崩溃机制分析文档
android
王六岁6 小时前
UIAutomatorViewer 安装指南 (macOS m3pro 芯片)
android studio
城东米粉儿6 小时前
关于ObjectAnimator
android
zhangphil7 小时前
Android渲染线程Render Thread的RenderNode与DisplayList,引用Bitmap及Open GL纹理上传GPU
android
火柴就是我8 小时前
从头写一个自己的app
android·前端·flutter
lichong9519 小时前
XLog debug 开启打印日志,release 关闭打印日志
android·java·前端