【java与智能设备】01_2Android简介与环境搭建——开发环境

*切换视图 文件作用 布局文件 *

  1. 配置JDK
  2. 安装Android Studio3.5
  3. 获得Android SDK
  4. Android Studio中配置Android SDK
  5. Gradle简介及配置

API是向后兼容的

gradle:用于打包 apk

system-images:系统镜像文件
包名:域名的倒叙

Grable的一些文件

视图(常见三个)

1. Android视图最常用

app对应开发一个应用程序常用到的文件

在这里插入图片描述

  1. manifests
  2. java
  • java下有三个目录,第一个为重点(有MainActivity),剩下两个是测试用的
  • MainActivity 是一个java源文件

在这里插入图片描述
在这里插入图片描述
3. res目录是重点(res:resource资源文件)
存放资源文件,除了java源代码文件,都叫资源文件

  • drawable 和 mipmap 存放图片资源
  • layout布局文件,完成界面样式(xml格式)
    • TextView:显示字符串的文本框,此处有显示helloworld相关的东西
      在这里插入图片描述
      图片资源存放在mipmap中
      在这里插入图片描述
  1. values资源(值资源):
    • colors.xml:颜色的rgb、strings.xml:字符串、styles.xml:样式
    • 都是xml文件

2. project视图(以项目名称为根):

  1. 展示的文件与硬盘的文件一致
    app中的src文件存放了java的源代码和资源文件,
    main中的java和src展开的目录和Android视图一样
    在这里插入图片描述

3.packages视图

以包的形式展示文件,只有一个app目录

Android程序结构

MainActivity

  1. 以后在这个文件进行修改,写java源代码
  2. @override注解:标识此方法重写了基类中的一个方法,调用的时候不需要手动调用,打开界面会自动调用(所以不需要再找main方法,已经存在了入口方法:onCreate)
  3. MainActivity是继承自Activity类的(当API大于19的时候默认继承APPCompatActivity,但最终是继承自Activity)
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

R.java

  1. 自动生成的一个文件,不需要程序员修改
  2. 通过R类(在project视图下)来引用资源文件 R类中静态成员layout(程序和资源文件的桥梁)
  3. R.资源类型.资源名称:R.layout.activity_main
  4. 每添加一条资源,就会在R类添加一条数据
  5. 在这里插入图片描述
    在这里插入图片描述

布局文件(xml格式)

  1. 第一行是版本号编码方式

  2. ConstraintLayout元素/节点

  3. 元素的属性、属性赋值方法(双引号)

  4. 通过 xmlns 引用命名空间 :

    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前缀是命名空间(前提是要有引用)

<?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">    //对比html

    <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>

字符串资源文件

AndroidCH01 定义应用的名称

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

manifest:清单文件(所有的)

  1. 包含整个应用程序中使用到的所有组件都要在这个文件注册,否则程序无法打开此组件
  2. 根元素:manifest
  3. 可以修改组件设定如换图标
  4. intent-filter中的 action和category 共同决定程序的启动界面对应的activity类
<activity android:name=".MainActivity">  //配置类名
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidch01">

    <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">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

grade

一个工程中至少有一个模块(module),一个模块(module)对应一个application

eclipse中的project对应as中的module
as中的project对应eclipse中的workspace
Project:build.gradle
Moudle1: build.gradle
Moudle2: build.gradle
Moudle3: build.gradle

logcat

输出日志信息

[V]:详细(Verbose)信息
[D]:调试(Debug)信息
[I]:通告(Info)信息
[W]:警告(Warn)信息
[E] :错误(Error)信息

发布了33 篇原创文章 · 获赞 5 · 访问量 685

猜你喜欢

转载自blog.csdn.net/u013140841/article/details/104355073