android - How Get height of the Status Bar and Soft Key Buttons Bar? -


is there way in android size of soft buttons bar , status bar togheter? or way go screen height without height of both these bars? (they not same, @ nexus 7 example)

height of status bar

the height of status bar depends on screen size, example in device 240 x 320 screen size status bar height 20px, device 320 x 480 screen size status bar height 25px, device 480 x 800 status bar height must 38px

so recommend use script status bar height

rect rectangle = new rect(); window window = getwindow(); window.getdecorview().getwindowvisibledisplayframe(rectangle); int statusbarheight = rectangle.top; int contentviewtop = window.findviewbyid(window.id_android_content).gettop(); int titlebarheight= contentviewtop - statusbarheight;  log.i("*** value :: ", "statusbar height= " + statusbarheight + " , titlebar height = " + titlebarheight);  

to height of status bar on oncreate() method of activity, use method:

public int getstatusbarheight() {        int result = 0;       int resourceid = getresources().getidentifier("status_bar_height", "dimen", "android");       if (resourceid > 0) {           result = getresources().getdimensionpixelsize(resourceid);       }        return result; }  

soft key buttons bar

this method useful in order set layout padding in android kitkat (4.4). using this, can avoid soft buttons bar overlapping on layout.

the getrealmetrics method available api 17 , +

@suppresslint("newapi") private int getsoftbuttonsbarheight() {     // getrealmetrics available api 17 , +     if (build.version.sdk_int >= build.version_codes.jelly_bean_mr1) {         displaymetrics metrics = new displaymetrics();         getwindowmanager().getdefaultdisplay().getmetrics(metrics);         int usableheight = metrics.heightpixels;         getwindowmanager().getdefaultdisplay().getrealmetrics(metrics);         int realheight = metrics.heightpixels;         if (realheight > usableheight)             return realheight - usableheight;         else             return 0;     }     return 0; } 

reference:

height of status bar in android

dimension of soft buttons bar


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -