Skip to content

Commit 4654e7b

Browse files
committed
适配 Android 11
1 parent 39fdd7d commit 4654e7b

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#### 集成步骤
1616

1717
dependencies {
18-
implementation 'com.hjq:toast:8.3'
18+
implementation 'com.hjq:toast:8.5'
1919
}
2020

2121
#### 初始化 Toast

ToastUtils.apk

25.4 KB
Binary file not shown.

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.toast.demo"
88
minSdkVersion 14
99
targetSdkVersion 28
10-
versionCode 83
11-
versionName "8.3"
10+
versionCode 85
11+
versionName "8.5"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {
@@ -24,7 +24,7 @@ dependencies {
2424
implementation project(':library')
2525
implementation 'com.android.support:appcompat-v7:28.0.0'
2626
// 标题栏:https://github.com/getActivity/TitleBar
27-
implementation 'com.hjq:titlebar:6.0'
27+
implementation 'com.hjq:titlebar:6.5'
2828
// 悬浮窗:https://github.com/getActivity/XToast
2929
implementation 'com.hjq:xtoast:5.5'
3030
// 内存泄漏捕捉:https://github.com/square/leakcanary

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ android {
77
defaultConfig {
88
minSdkVersion 3
99
targetSdkVersion 26
10-
versionCode 83
11-
versionName "8.3"
10+
versionCode 85
11+
versionName "8.5"
1212
}
1313
}
1414

1515
publish {
1616
userOrg = 'getactivity'
1717
groupId = 'com.hjq'
1818
artifactId = 'toast'
19-
version = '8.3'
19+
version = '8.5'
2020
description = 'This is a very functional Toast'
2121
website = "https://github.com/getActivity/ToastUtils"
2222
}

library/src/main/java/com/hjq/toast/ToastUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ public static void init(Application application, IToastStyle style) {
6868

6969
// 初始化吐司
7070
if (areNotificationsEnabled(application)) {
71-
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
71+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + 4) {
72+
// 适配 Android 11 无法使用自定义 Toast 的问题
73+
// 官方文档:https://developer.android.google.cn/preview/features/toasts
74+
setToast(new SupportToast(application));
75+
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
7276
// 解决 Android 7.1 上主线程被阻塞后吐司会报错的问题
7377
setToast(new SafeToast(application));
7478
} else {

0 commit comments

Comments
 (0)