一、Android 概念
Android是开放式的手机和电脑操作系统,是基于Linux系统做的上层开发。
android可以做些什么?
Android可以开发各种手机应用APP,也可以开发车载系统等,在每一个领域中都有应用,已经在各大领域扮演重要角色。
二、Android 在物联网大赛中的具体实践
在物联网参赛说明中如此描述,物联网移动应用开发:基于 Android 开发平台,综合运用软件工 程、Android、嵌入式数据库等基础知识,完成 Android 嵌入式应用程序的开发,考察选手传感器技术、条码技术、ModBus 协议、基于网关数据采集技术、基于云平台设备接口开发等物联网综合移动设计开发能力
例:餐厅环境监控子系统开发
三、Android 开发环境搭建
Android环境搭建需要完成软件安装:一JDK、Android Studio、Android SDK
1、JDK安装和配置环境
JAVA_HOME
E:\Java\JDK
Path
%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
2、Android Studio 安装(注意需要足够的C盘)
点击net直接安装即可,在导入部分选择不导入
3、默认会加载SDK,如果想要选择自己的SDK,那么你需要做出以下步骤
File>>Project Structure >>SDK
4、选择JDK位置
File>>Project Structure >>JDK
5、安装虚拟机,点击右上角AVD Manager(在电脑上运行的模拟手机简称AVD)
五、运行第一个android应用
File>>New Project
创建的项目结构如下
参考文档
https://www.jianshu.com/p/4962b4eeec63
项目运行如下
六、运行android程序可能出现的问题
1、不支持3.8
在build.gradle中去掉相关导入
2、无法生成APK,将app下的buid删除
3、无法生存apk,apk为空
File>> setting>> buid >> Instent run 勾选去掉
七、布局文件介绍
ConstraintLayout布局概述:
ConstraintLayout是约束布局,从主流布局上来讲,将会成为主流的布局,和相对布局非常类似,但比相对布局更为流畅,约束布局最适合的手动拖动控件布局。
使用方式方式和属性说明:
1、添加项目依赖
implementation 'com.android.support.constraint:constraint-layout:2.0.1'
八、常见的android布局和控件
android中有常见的几大布局:LinearLayout线性布局、RelativeLayout相对布局、AbsoluteLayout绝对布局、GridLayout网格布局。
1、weight权重讲解
权重:就是在布局界面中所占的比例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#f47920">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#2a5caa">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#faa755">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="请输入姓名"/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:text="请输入密码"
android:layout_height="60dp" />
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="登录"
android:background="#00a6ac"/>
</LinearLayout>
常见的android控件 TextView 只读的文本控件 Plain Text 可输入的文本控件
Button 按钮控件
九、Android项目Src源码
在源码中有一个MainActivity.java文件,文件打开如下
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//调用父类的onCreate方法
super.onCreate(savedInstanceState);
//设置layout中对应的XML文件activity_main
setContentView(R.layout.activity_main);
//获取登录按钮
Button btn =(Button) findViewById(R.id.Login);
//设置按钮的监听事件
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//设置Text为本显示hello和日期
TextView show= (TextView) findViewById(R.id.show);
show.setText("hello"+new java.util.Date());
}
});
}
}
一:设置Activity使用的xml文件布局
二:获取ID为R.id.Login的按钮
三:将事件绑定在R.id.show的文本框中(其中findViewById其实是相当于js中的getElementById)
Java其实可以理解为Android应用资源字典
Res目录说明:res存放Android应用所用的全部资源,包括图片资源、字符串资源、颜色资源、尺寸资源等。
所有的资源都会在R.java中生成资源清单。
XML文件介绍:XML文件定义可用于定义常用的资源。
引用资源形式如下:@xml文件名/定义的xml文件,比如使用使用color中的定义的颜色
注意:定义的id标识符,不需要专门的xml资源定义
@+id/<标识符名称>
AndroidManifest.xml清单文件:(可在mainfest中配置权限、比如电话权限、录音权限等)
<!--指定Android应用包名 该包名可用于唯一表示该应用-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.administrator.demo2">
<!--指定Android应用标签、图标等-->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--定义Android应用的一个组件:-->
<activity android:name=".MainActivity">
<intent-filter>
<!--指定Activity是程序入口-->
<action android:name="android.intent.action.MAIN" />
<!--指定加载应用时运行该Activity-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>