版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangwenhaojf40it/article/details/79694601
-
- 1.dagger2配置
- 2.在stuiod3.0下开启Lambda表达式
- 3.一行文字多种颜色
- 4.android js 方法互掉
- 5.studio 中DataBinding使用
- 6.将项目中module变成library引用依赖
- 7.阿里路由框架ARout添加
- 8.浏览器cookie存放位置
- 9.A应用启动B应用
- 10.Kotlin直接使用id,不用findViewById
- 11.通过包名启动另一个应用
- 12.studio 去除版本控制
- 13.getColor过时
- 14.一行文字中多种颜色
- 15.8.0适配 通知栏
- 16.8.0适配 安装未知来源
- 17.浏览github窗口左边显示目录结构
- 18.studio中报错,运行命令查看详细信息
1.dagger2配置
- 如果是在2.3上 需要引入插件
1.在根项目 build.gradle中配置
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’
2.module级别下的build.gradle中在最顶部引入插件
apply plugin: ‘com.neenbedankt.android-apt’
3.依赖
compile ‘com.google.dagger:dagger:2.6’
apt ‘com.google.dagger:dagger-compiler:2.6’ - 如果在3.0下 直接在modlue 级别build.gradle 下 依赖即可
compile ‘com.google.dagger:dagger:2.11’
annotationProcessor ‘com.google.dagger:dagger-compiler:2.11’
2.在stuiod3.0下开启Lambda表达式
defaultConfig {
···
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
3.一行文字多种颜色
SpannableStringBuilder span = new SpannableStringBuilder("我们都是好孩子");
span.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this,R.color.font_black)), 0, content.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tvDanger.setText(span);
4.android js 方法互掉
//js调用android
//js 中写 window.android.quit()
//记得 代码中 设置
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
//添加js互掉的方法
mWebView.addJavascriptInterface(new JsInteration(this), "android");
public class JsInteration{
@JavascriptInterface
public void quit() {
act.finish();
}
}
//android 调用js
mWebView.loadUrl("javascript:pageUp()");
5.studio 中DataBinding使用
android {
......
dataBinding {
enabled = true
}
........
}
6.将项目中module变成library引用依赖
选择你想作为library的module。选择build.gradle文件将最上方的代码apply plugin: ‘com.android.application’改为apply plugin: ‘com.android.library’。
并删除defaultConfig下的 applicationId “yy.hao.com.selfview”
依赖module
7.阿里路由框架ARout添加
1.添加依赖。
android {
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [ moduleName : project.getName() ]
}
}
}
}
//ARouter 依赖
compile 'com.alibaba:arouter-api:1.3.1'
annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
2.Application中初始化
ARouter.init(this);
3. ARouter.getInstance().build("/Activity/NewsActivity")
.navigation();
4.要跳转的NewsActivity设置映射
下图所示:
8.浏览器cookie存放位置
- 火狐浏览器cookie存放位置
C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\pjajm1nj.default
下cookies.sqlite - Chrome浏览器cookie存放位置
C:\Users\jay\AppData\Local\Google\Chrome\User Data\Default\Cookies
9.A应用启动B应用
Intent intent = new Intent(Intent.ACTION_MAIN);
ComponentName cn = new ComponentName("com.bao","com.bao.MainActivity");
intent.setComponent(cn);
//或者 直接
//intent.setClassName("com.bao","com.bao.MainActivity");
startActivity(intent);
10.Kotlin直接使用id,不用findViewById
- 需要再app Module 下build.gradle中 引入插件
//顶部引入
apply plugin:'kotlin-android-extensions'
11.通过包名启动另一个应用
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("hao.wen.zhang.plugin");
if (intent == null) {
Toast.makeText(MainActivity.this, "未安装", Toast.LENGTH_SHORT).show();
} else {
startActivity(intent);
}
12.studio 去除版本控制
13.getColor过时
ContextCompat.getColor(this,R.color.red)
14.一行文字中多种颜色
SpannableString spann = new SpannableString("恭喜您获得2000元体验金");
spann.setSpan(new ForegroundColorSpan(Color.parseColor("#F35B10")),5,10,Spanned.SPAN_INCLUSIVE_INCLUSIVE);
tv.setText(spann);
四种Flag值 含义:
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE --- 不包含两端start和end所在的端点
Spanned.SPAN_EXCLUSIVE_INCLUSIVE --- 不包含端start,但包含end所在的端点
Spanned.SPAN_INCLUSIVE_EXCLUSIVE --- 包含两端start,但不包含end所在的端点
Spanned.SPAN_INCLUSIVE_INCLUSIVE--- 包含两端start和end所在的端点
15.8.0适配 通知栏
@TargetApi(Build.VERSION_CODES.O)
@Override
public void notifyAdaper() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("push_id", getString("推送消息"), NotificationManager.IMPORTANCE_HIGH);
NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
}
16.8.0适配 安装未知来源
清单文件中增加权限: 该权限无需动态申请
<!--8.0 未知来源适配-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
跳转打开未知来源开关
/*
*
* 适配8.0
* 申请未知应用安装
* */
@Override
public void requestPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//是否允许 安装未知应用
boolean isInstallPermission = getPackageManager().canRequestPackageInstalls();
if (!isInstallPermission) { //没有 同意 则跳转开启
Uri packageURI = Uri.parse("package:" + getPackageName());
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
startActivityForResult(intent, Constant.REQUEST_CODE_INSTALL);
} else {//更新逻辑
...
}
} else { //更新逻辑
...
}
}
17.浏览github窗口左边显示目录结构
安装插件OctoTree,
Chrome商店,中搜索OctoTree
火狐浏览器同样也可以
18.studio中报错,运行命令查看详细信息
gradlew compileDebugSources --stacktrace -info