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.
According to Material Guidance; height of status bar is 24 dp.
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:
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With