安卓问题

120 阅读2分钟
  1. Application 类是什么
    全局配置变量可以放这,是个单例模式
  1. AppCompatActivity 与 Activity 区别
  2. colorPrimaryDark与statusBarColor的异同
  3. intent 隐世用法
  4. Android 中的mipmap 和drawable的区别
  5. Timer java中的定时器类
  6. 布局中注意: 区分“android:gravity”和“android:layout_gravity”
  7. dp与sp区别
  8. Android Studio快速生成set get以及构造方法的快捷方式 【通过快捷键Alt+Insert】
  9. 自定义控件流程
  10. declare-styleable 和 style 的区别
  11. context.obtainStyledAttributes 是作用
  12. LayoutInflater.from(context).inflate 布局填充器
  13. drawable 具体干嘛用的
  14. android context 与 this 区别
  15. intent 标识符
  16. AppCompatImageView 是什么
    1. context 本身是抽象类,activity service 都继承context,所有可以直接使用context,即this
  17. 安卓 handle 类
  18. 基于回调事件处理 基于监听事件处理
  19. 两个 build.gradle 说明
最外层(一般无需修改)
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter() // 代码仓库
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3' // gradle专门用来做安卓解析插件
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
app内层
apply plugin: 'com.android.application' // com.android.application 表示这个是应用程序模块,可直接运行 com.android.library 表示一个库模块,依附别的程序运行 

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.example.firstlinecode20" // 用于指定项目的包名
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

22 安卓任何控件有 View.GONE View.VISIBLE View.INVISIBLE 三种状态

第五章 广播

1 标准广播 异步通知 2 有序广告 同步通知

public class ReceiverActivity extends AppCompatActivity {

    private IntentFilter intentFilter;
    private NetworkChageReceiver networkChageReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receiver);
        intentFilter = new IntentFilter();
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        // 添加个action 
        networkChageReceiver = new NetworkChageReceiver();
        // 注册次昂贵action,并且执行相关NetworkChageReceiver里的方法
        // 系统每次这个action变化时候,自动
        registerReceiver(networkChageReceiver,intentFilter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(networkChageReceiver);
    }

    class NetworkChageReceiver extends BroadcastReceiver{
         // 重写方法 onReceive
        @Override
        public void onReceive(Context context, Intent intent) {
            ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
            if(networkInfo != null){
                Toast.makeText(context,"network aviable",Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(context,"network unviable",Toast.LENGTH_LONG).show();
            }


        }
    }
}

6章 安卓持久化

7章 内容提供器