Android开发-Android APP实操-1.项目创建及启动页面UI编码
一、项目创建及模拟器安装
1.选择新建一个project
2. 选择空模板
3.完成新project的设置
下载完成后点击Finish
4.下载安卓模拟器
选择Pixel7
点击下载R
为虚拟机命名,选择竖屏,点击Finish.
5.点击启动,测试运行
运行成功!
二、启动页面UI编码
1.打开MainActivity.java文件,Ctrl+左键进入activity_main.xml
2.在activity_main.xml中点击右键,进入xml编写UI页面模式
3.修改activity_main.xml的代码,识别手写xml
<?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" tools:context=".MainActivity"> </RelativeLayout>
4.AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyApplication1" tools:targetApi="31"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
activity_main:
<?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" android:background="@mipmap/ic_launcher" tools:context=".MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="44dp" android:paddingRight="44dp" android:layout_alignParentBottom="true" android:layout_marginBottom="90dp"> <Button android:layout_alignParentLeft="true" android:layout_width="100dp" android:layout_height="50dp" android:text="@string/login" android:textSize="20sp" android:textColor="#ffffff" android:background="@drawable/shape_login_btn"/> <Button android:layout_alignParentRight="true" android:layout_width="100dp" android:layout_height="50dp" android:text="@string/register" android:textSize="20sp" android:textColor="#ffffff" android:background="@drawable/shape_register_btn"/> </RelativeLayout> </RelativeLayout>
strings.xml:
<resources> <string name="app_name">MyApplication1</string> <string name="login">登录</string> <string name="register">注册</string> </resources>
shape_login_btn.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="9dp" /> <solid android:color="#c75fe768" /> </shape>
shape_register_btn.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="9dp" /> <solid android:color="#c75fe768" /> </shape>
5.启动运行
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
2023-03-27 Android开发-Android常用组件-EditText输入框