Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 73c55cb

Browse files
katherine95sYorkShen
authored andcommitted
[Android] fix Android9 inaccurate ScreenHeight problem (#2536)
* [Android] fix Android9 inaccurate SreenHeight problem
1 parent b07f49c commit 73c55cb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.graphics.Canvas;
2525
import android.graphics.Path;
2626
import android.graphics.PixelFormat;
27+
import android.graphics.Point;
2728
import android.graphics.RectF;
2829
import android.graphics.drawable.Drawable;
2930
import android.graphics.drawable.LayerDrawable;
@@ -36,6 +37,8 @@
3637
import android.view.View;
3738
import android.view.ViewGroup;
3839
import android.view.ViewGroup.LayoutParams;
40+
import android.view.WindowManager;
41+
3942
import com.taobao.weex.WXEnvironment;
4043
import com.taobao.weex.WXSDKInstance;
4144
import com.taobao.weex.WXSDKManager;
@@ -206,8 +209,17 @@ public static int getScreenHeight() {
206209

207210
public static int getScreenHeight(Context cxt) {
208211
if(cxt!=null){
212+
WindowManager wm;
209213
Resources res = cxt.getResources();
210-
mScreenHeight =cxt.getResources().getDisplayMetrics().heightPixels;
214+
if(Build.VERSION.SDK_INT >= 28 && (wm = (WindowManager)cxt.getSystemService(Context.WINDOW_SERVICE)) != null
215+
&& wm.getDefaultDisplay() != null){
216+
Point size = new Point();
217+
wm.getDefaultDisplay().getRealSize(size);
218+
mScreenHeight = size.y;
219+
}
220+
else {
221+
mScreenHeight = cxt.getResources().getDisplayMetrics().heightPixels;
222+
}
211223
if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
212224
mScreenWidth = res
213225
.getDisplayMetrics()

0 commit comments

Comments
 (0)