java - Android: How to find width and height of screen? -


i trying find width , height of screen none of ways have tried work in class created, code below.

does know how find it? cannot use way trying below because .getwidth() deprecated?

public class crate {      public int acrosscrate;     public int updowncrate;     context thecontext;      windowmanager wm = (windowmanager)thecontext.getsystemservice(context.window_service);     display display = wm.getdefaultdisplay();     int width = display.getwidth();       public crate() {     acrosscrate = 650;     updowncrate = 650;     //int width = ;     //int height = ;    }  }  

use below code

private int getscreenheight(context context) {         int height;          if (android.os.build.version.sdk_int >= 13) {             windowmanager wm = (windowmanager) context.getsystemservice(context.window_service);             display display = wm.getdefaultdisplay();             point size = new point();             display.getsize(size);             height = size.y;         } else {             windowmanager wm = (windowmanager) context.getsystemservice(context.window_service);             display display = wm.getdefaultdisplay();             height = display.getheight();  // deprecated         }          return height;     } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -