Android开发小知识点笔记(不定时)

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" />

注意,不需要加文件后缀。网上的例子都是加上的,但实际不起作用,需要去掉文件后缀

未完待续…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值