CustomToast
- github: https://github.com/hanjx-dut/CustomToast
Android 11 中将禁止使用自定义 View 的 Toast
一种简单的解决思路是通过在 DecorView 中动态添加删除 View,加入淡入、淡出、滑动的动画效果,实现自定义 View 的 Toast 效果。本文是简单实现。
- 普通 Toast 样式:CustomToast、SimpleToast
- 类似系统通知的横幅效果:NotificationToast
引入依赖
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.hanjx-dut:CustomToast:Tag'
}
使用
// SimpleToast 底部 Toast,类似原生文字 Toast
SimpleToast.toastShort(textView3);
// SimpleToast.toastLong(textView3);
// SimpleToast.toastTime(textView3, 1000);
// CustomToast 可自定义位置,持续