Unit1 The first code

Unit1 The first code

1.1 Android系统架构

1、Linux内核,为设备的硬件提供底层驱动,如显示、音频、照相机、蓝牙、WiFi驱动等。

2、系统运行库层,通过C/C++库为系统提供主要特性支持,且还有Android运行时库,提供核心库,允许开发者使用Java语言编写应用。

3、应用框架层,提供各种API。

4、应用层,应用程序。

Android应用开发特色:

1、四大组件:Activity、Service、BroadcastReceiver、ContentProvider。
Activity:表层界面。
Service:后台运行。
BroadcastReceiver:接发广播信息。
ContentProvider:实现应用程序间的共享数据。

2、丰富的系统控件。

3、SQLite数据库:轻量级、运算速度极快的嵌入式关系型数据库。

4、强大的多媒体:丰富的多媒体服务。

1.2 HelloWorld项目执行过程分析

1、app.src.main.res.AndroidMainfest.xml 整个Android项目的配置文件。

<activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

上述代码对MainActivity进行注册,没有在AndroidMainfest.xml中注册的Activity注册的Activity是无法使用的。

2、app.src.main.java.com.example.helloworld.MainActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

P.S.Android程序的设计讲究逻辑和试图分离,不推荐在Activity中直接编写界面。

由setContentView(R.layout.activity_main)可以看出该setContentView()方法给当前的Activity引入activity_main布局,则"Hello World!"在此定义。

3、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:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

控件Textview中的"Hello World"

1.3 详解内容

"drawable"开头的目录是用以存放图片
"mipmap"开头的目录是用以存放应用图标
"values"是用以存放字符串、样式、颜色等配置
"layout"是用以存放布局文件

1、使用资源方式:

1)定义一个应用程序名的字符串

<resources>
    <string name="app_name">HelloWorld</string>
</resources>

​ 2)引用该字符串
在代码中通过 R.string.app_name 可以获得该字符串的引用
在XML中通过 @string/app_name 可以获得该字符串的引用

2、详解 build.gradle文件略,详情见书P22

1.4 掌握日志工具的使用

使用Android的日志工具Log,减少sout和println()的使用
等级:Log.v()—>Log.d()—>Log.i()—>Log.w()—>Log.e()
详情见书P25

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值