Android学习笔记
安装Androidstudio注意事项:
Androidstudio常用快捷键:https://www.cnblogs.com/kangyi/p/4246117.html
Androidstudio常用插件:https://www.open-open.com/lib/view/open1480329318348.html
Androidstudio常用设置:https://blog.csdn.net/weixin_39251617/article/details/79869586
Androidstudio真机调试时出现mainSDK(API 28)>devicesdk(API 25): https://blog.csdn.net/languobeibei/article/details/78293497
Androidstudio SDK开发帮助文档:http://www.pansoso.com/d/225046/
开发前的配置
配置build.gradle(Module:app):
版本间关系: minSdkVersion <= targetSdkVersion <= compileSdkVersion <= buildToolsVersion
理想版本关系: minSdkVersion <= targetSdkVersion == compileSdkVersion == buildToolsVersion:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.helloworld.lq.helloworld"
minSdkVersion 22
targetSdkVersion 26
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:26.+'
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'
}添加gradle:file:///C:/Users/Administrator/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/gradle-4.6-all.zip
(一)目录文件:
\Hello\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\com\example\hello\R.java文件不可修改,res文件下 的资源会在R.java中自动生成id(使用src文件中的资源直接引用R.xxx)几个内部类
\Hello\app\src\main\res\drawable:放置图片(不同的分辨率)
\Hello\app\src\main\res\layout文件:为activity配置布局
\Hello\app\src\main\res\values文件:放置键值对(为国际化语言考虑)
\Hello\app\src\main\AndroidManifest.xml文件是配置整个应用程序
<android:icon配置应用程序的图标。。。
<android:label配置应用程序的标签。。。
配置activity:
<activity android:name=".Hello1Activity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
(二)Activity
1,作用:可见的,用户和应用程序之间的交互接口,放置不同的控件(控件的容器)
2,activity要点:
①activity是一个类,需要继承Activity
②需要复复写onCreate()方法
③AndroidManifest.xml文件中会出现activity配置
Component name:指定一个请求跳转到另一个activity的名字
Action:指定跳转的activity的行为(如Intent.ACTION_SENDTO是一个发短信的行为)
Date:传递的数据(uri类型)
Extras:放置一些键值对
//点击MainActivity的按钮,跳转到Hello1Activity
package com.example.hello;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
private Button bt_a;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt_a=(Button) findViewById(R.id.bt_a);
bt_a.setOnClickListener(new Bt_aListener());
}
class Bt_aListener implements View.OnClickListener//设置按钮的监听器,实现跳转功能
{
@Override
public void onClick(View v)
{
Intent intent=new Intent();
intent.setClass(MainActivity.this, Hello1Activity.class);
MainActivity.this.startActivity(intent);//传参
}
}
package com.example.hello;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;public class Hello1Activity extends AppCompatActivity { private TextView tv_b=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello1); /* Intent intent=getIntent(); String data=intent.getStringExtra("data1");*/ tv_b=(TextView) findViewById(R.id.tv_b); //tv_b.setText(data); tv_b.setText(R.string.HelloActivity); }}