Android开发小知识点笔记(不定时)
Dialog背景色透明
<style name="ShareDialogStyle" parent="android:style/Theme.Dialog">
<!--无标题-->
<item name="android:windowNoTitle">true</item>
<!--边框-->
<item name="android:windowFrame">@null</item>
<!--背景-->
<item name="android:windowBackground">@color/transparent</item>
<!--是否背景变暗-->
<item name="android:backgroundDimEnabled">true</item>
<!--透明度-->
<item name="android:backgroundDimAmount">0.3</item>
</style>
View保存为Bitmap
推荐这个方式,不在显示区域也可以生成bitmap
Bitmap bitmapBig = Bitmap.createBitmap(page.getWidth(),page.getHeight(), Bitmap.Config.RGB_565);
page.draw(new Canvas(bitmapBig));
Matrix matrix = new Matrix();
float scal = 750 * 1.0f / bitmapBig.getWidth();
matrix.setScale(scal, scal);
Bitmap bitmap = Bitmap.createBitmap(bitmapBig, 0, 0, bitmapBig.getWidth(),bitmapBig.getHeight(), matrix, true);
更新系统图片库
保存完图片之后通知系统相册刷新
MediaScannerConnection.scanFile(activity.getApplicationContext(),
new String[]{path}, null, null);
文件流与字节流
FileOutputStream 字节输出流
BufferedOutputStream 字节缓冲输出流,继承FileOutputStream,多了一套缓冲机制,
缓冲可以减产硬盘操作次数,提高效率
byte buff[] = new byte[size]
BufferedOutputStream中的size默认8192
OutputStreamWriter 字符转字节输出流
BufferedWriter 字符缓冲输出流
可以保证字符写入不会乱码
(英文占用一个字节,中文占用两个字节)
引用的资源包版本冲突
各位在引入不同的第三方文件之后,可能会遇到如下错误:
Android dependency ‘com.android.support:recyclerview-v7’ has different version for the compile (25.3.1) and runtime (25.4.0) classpath. You should manually set the same version via DependencyResolution
configurations.all{
resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.11.0'
resolutionStrategy.force 'com.android.support:support-v4:27.1.1'
resolutionStrategy.force 'com.android.support:recyclerview-v7:27.1.1'
}
遇到的小伙伴们可以尝试一下
开启资源优化的正确姿势
app下的build.gradle文件加上
minifyEnabled true
shrinkResources true
查看proguard文件中是否有dontshrink,有请注释
#-dontshrink
在res/raw目录下创建keep.xml文件,配置忽略文件
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@xml/config,
@raw/beep,
@xml/nnf_provider_paths"
tools:shrinkMode="safe" />
注意,不需要加文件后缀。网上的例子都是加上的,但实际不起作用,需要去掉文件后缀
未完待续…