sunjinbo sunjinbo - 4 months ago 5x
Android Question

How to get the screen resolution including the size of soft keyboard?

My phone is HUAWEI NXT-AL10, and I can see its resolution is 1080 x 1920 from the system settings page, But when I try to writing some codes as below to retrieving its screen resolution, the value is 1080 x 1794, I guess maybe it doesn't include the size of soft-keyboard. So How can I get the resolution just like as the settings page said (1080 x 1920)?

DisplayMetrics metric = new DisplayMetrics();
int width = metric.widthPixels;
int height = metric.heightPixels;


The code below should give you what you're looking for

Point size = new Point();
iWidth = size.x;
iHeight = size.y;

Log.i(TAG, "Screen real size (pixels) :width = " + iWidth);
Log.i(TAG, "Screen real size (pixels) :height = " + iHeight);

Note that this requires API 17 and above