Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of android notification bar and title bar?

Tags:

Is there a way to obtain the size of the notification bar and title bar in android? At the moment I obtain the display width and height with:

Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); 

After that I want to subtract the sizes of the bars so that I can stretch a video without losing aspect ratio. Currently I hide the bars because I can't see a better way.

like image 657
lalalei Avatar asked Aug 30 '10 13:08

lalalei


People also ask

What is the size of status bar?

According to Material Guidance; height of status bar is 24 dp.


1 Answers

Maybe this is a helpful approach: Referring to the Icon Design Guidelines there are only three different heights for the status (notification) bar depending on the screen density:

  • 24px for LDPI
  • 32px for MDPI
  • 48px for HDPI

So if you retrieve the screen density of the device using densityDpi of DisplayMetrics you know which value to subtract

so it could look something like that:

    DisplayMetrics metrics = new DisplayMetrics();     getWindowManager().getDefaultDisplay().getMetrics(metrics);     int myHeight = 0;      switch (metrics.densityDpi) {         case DisplayMetrics.DENSITY_HIGH:             Log.i("display", "high");             myHeight = display.getHeight() - 48;             break;         case DisplayMetrics.DENSITY_MEDIUM:             Log.i("display", "medium/default");             myHeight = display.getHeight() - 32;             break;         case DisplayMetrics.DENSITY_LOW:             Log.i("display", "low");             myHeight = display.getHeight() - 24;             break;         default:             Log.i("display", "Unknown density"); 
like image 60
DonGru Avatar answered Nov 01 '22 00:11

DonGru