Skip to content

Commit c23ac90

Browse files
committed
Create AutoSizeConfig#setStatusBarHeight
1 parent a159646 commit c23ac90

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

autosize/src/main/java/me/jessyan/autosize/AutoSizeConfig.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ public final class AutoSizeConfig {
8888
* 设备的屏幕总高度, 单位 px, 如果 {@link #isUseDeviceSize} 为 {@code false}, 屏幕总高度会减去状态栏的高度
8989
*/
9090
private int mScreenHeight;
91+
/**
92+
* 状态栏高度, 当 {@link #isUseDeviceSize} 为 {@code false} 时, AndroidAutoSize 会将 {@link #mScreenHeight} 减去状态栏高度
93+
* AndroidAutoSize 默认使用 {@link ScreenUtils#getStatusBarHeight()} 方法获取状态栏高度
94+
* AndroidAutoSize 使用者可使用 {@link #setStatusBarHeight(int)} 自行设置状态栏高度
95+
*/
96+
private int mStatusBarHeight;
9197
/**
9298
* 为了保证在不同高宽比的屏幕上显示效果也能完全一致, 所以本方案适配时是以设计图宽度与设备实际宽度的比例或设计图高度与设备实际高度的比例应用到
9399
* 每个 View 上 (只能在宽度和高度之中选一个作为基准), 从而使每个 View 的高和宽用同样的比例缩放, 避免在与设计图高宽比不一致的设备上出现适配的 View 高或宽变形的问题
@@ -131,7 +137,7 @@ public final class AutoSizeConfig {
131137
*/
132138
private boolean isMiui;
133139
/**
134-
* Miui系统中的 mTmpMetrics 字段
140+
* Miui 系统中的 mTmpMetrics 字段
135141
*/
136142
private Field mTmpMetricsField;
137143
/**
@@ -199,6 +205,7 @@ AutoSizeConfig init(final Application application, boolean isBaseOnWidth, AutoAd
199205
int[] screenSize = ScreenUtils.getScreenSize(application);
200206
mScreenWidth = screenSize[0];
201207
mScreenHeight = screenSize[1];
208+
mStatusBarHeight = ScreenUtils.getStatusBarHeight();
202209
LogUtils.d("designWidthInDp = " + mDesignWidthInDp + ", designHeightInDp = " + mDesignHeightInDp + ", screenWidth = " + mScreenWidth + ", screenHeight = " + mScreenHeight);
203210

204211
mInitDensity = displayMetrics.density;
@@ -413,7 +420,7 @@ public int getScreenWidth() {
413420
* @return {@link #mScreenHeight}
414421
*/
415422
public int getScreenHeight() {
416-
return isUseDeviceSize() ? mScreenHeight : mScreenHeight - ScreenUtils.getStatusBarHeight();
423+
return isUseDeviceSize() ? mScreenHeight : mScreenHeight - mStatusBarHeight;
417424
}
418425

419426
/**
@@ -574,6 +581,17 @@ public AutoSizeConfig setDesignHeightInDp(int designHeightInDp) {
574581
return this;
575582
}
576583

584+
/**
585+
* 设置状态栏高度
586+
*
587+
* @param statusBarHeight 状态栏高度
588+
*/
589+
public AutoSizeConfig setStatusBarHeight(int statusBarHeight) {
590+
Preconditions.checkArgument(statusBarHeight > 0, "statusBarHeight must be > 0");
591+
mStatusBarHeight = statusBarHeight;
592+
return this;
593+
}
594+
577595
/**
578596
* 获取使用者在 AndroidManifest 中填写的 Meta 信息
579597
* <p>

0 commit comments

Comments
 (0)