jiang111

some code tips for android ?
Under Apache License 2.0
By jiang111

android awesome tips




EnglishVersion ->_->:https://github.com/jiang111/awesome-android-tips/blob/master/README-en.md


值得收藏的AS插件 ->_->:https://github.com/jiang111/awesome-androidstudio-plugins


这里收集了大家常用的一些Android代码,持续更新中,内容来自自己的平时积累和网络上看到的文章,部分原文地址在最下方。如有错误欢迎指正,如有侵权,请联系我删除。里面可能会有重复内容,请忽略或者提醒我删除。



*备注:大家注意看到有一些NO上添加了一些数字,其实这些从能力上来说是YES,但是为什么说是NO呢?下面一个一个解释:
1. 数字1:启动Activity在这些类中是可以的,但是需要创建一个新的task,一般情况不推荐;
2. 数字2:在这些类中去layout inflate是合法的,但是会使用系统默认的主题样式,如果你自定义了某些样式可能不会被使用;
3. 数字3:在Receiver为null时允许,在4.2或以上的版本中,用于获取黏性广播的当前值。(可以无视);
4. ContentProvider、BroadcastReceiver之所以在上述表格中,是因为在其内部方法中都有一个context用于使用。



wrap_content
wrap_content

```
这样,控件的宽高默认都是wrap_content样式啦。


fill_parent
fill_parent

vertical

```





```



```



```



```
配置正常的multiDex库之后,在主模块的gradle文件添加如下代码:
Android{
...//其他代码
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
additionalParameters += '--multi-dex'
additionalParameters += '--set-max-idx-number=35000'//(35000可根据自己的需求更改)来适配4.0-4.4一些低端机型,因为拆分的dex太大,这些低端机型加载不了dex
additionalParameters += '--minimal-main-dex'
}


}
```


注意:在gradle版本3.1.0之后dex编译采用D8,可能会导致这种分包不成功。将gradle的版本降到3.0.0之后,分包成功。另外也可以采用gradle3.1.0或者以上的版本,然后将项目的gradle配置为android.enableD8=false //暂时关闭 即可



当然,依赖替换规则还允许我们在本地库和远程库之间进行切换.
configurations.all {
resolutionStrategy.dependencySubstitution {
if (useLocal) { //如果使用本地仓库,系统将会把org.utils:api依赖替换为本地api的project
substitute module("org.utils:api") because "we work with the unreleased development version" with project(":api")
}
}
}
```



摘自如下地址
捐赠

如果您觉得本项目对您有帮助,欢迎请作者一杯咖啡



License
Copyright 2018 NewTab

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.