android开发 笔记(1.3)
活动注册
分析helloworld代码
HelloWorldActivity活动进行注册
<activity android:name=".HelloWorld">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
引用图标 字符等的操作
<resources>
<string name="app_name">Demo1</string>
</resources>
代码中 通过R.string.hello_world可以获得该字符串的引用
在xml中 通过@string/hello_world可以获得该字符串的引用
引用图片/图标/布局文件可以分别把string换成drawable/mipmap/layout
例如:
android:icon="@string/ic_launcher"
详解build.grade
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
1.jcenter是一个代码托管仓库,声明了这一行代码就可以在项目中轻松的引用任何rcenter上的开源项目了
2.dependencies闭包中使用classpath声明一个Gradle插件
因为Grade不是只面向android的
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.demo1"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
1.com.android.application&&com.android.library 应用程序模块&&库模块
前者可以直接运行 后者必须依附别的应用程序模块来运行
2. defaultConfig闭包中:
minSdkVersion 15 targetSdkVersion 28
最低兼容到android 4.0
3.buildTypes闭包 用于指定生成安装文件的相关配置
4.dependencies 闭包
fileTree(dir: ‘libs’, include: [’*.jar’]) 本地依赖声明 libs目录中所有.jar后缀文件都添加到项目的构建路径之中
‘com.android.support:appcompat-v7:28.0.0’ 远程依赖声明
testImplementation 声明测试用例库 暂时用不到
使用android日志工具Log
类似:
快捷键 logd logi
一般最简单的是在onCretate外打logt
在logcat中找到关键信息:
logcat中只有三个过滤器
只显示当前选中的程序日志/谷歌提供的一个分析工具/显示所有/自定义
logcat中的日志级别控制
逐个级递增。