Rob Avery IV
Rob Avery IV

Reputation: 3740

Alternative to DISPLAY.getWidth()

I know the Display method getWidth() has been deprecated since API 13. I have the following line of code:

Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int displayWidth = display.getWidth();

What is the alternative for API Level 13 and above?

Upvotes: 1

Views: 2768

Answers (2)

rotterick
rotterick

Reputation: 384

In case you're not in an activity use

context.getResources().getDisplayMetrics().heightPixels;
context.getResources().getDisplayMetrics().widthPixels;

Upvotes: 2

Mr. Developerdude
Mr. Developerdude

Reputation: 9678

You are looking for getSize(Point outSize) (according to official android API documentation )

Hope this helps!

Upvotes: 1

Related Questions