How to get the height of StatusBar (Android platform)

Source: Internet
Author: User

By default, the height of the statusbar is 25dip, this value will not change, whether your screen is 240*320 or 600*800 or other resolutions, StatusBar height is 25dip.
Perhaps some students will say, how could it be, the value of 600*800 equipment on the statusbar height is obviously much higher!
Yes, the value of 600*800 such a device, the height of StatusBar looks really much higher than the 240*320 screen, but it is indeed 25dip, but at this time it is not 25px.

On the device of 240*320 resolution, 25DIP, when displayed on the device, its length or height is 25 pixels, that is 25px, but on the 600*800 device, this 25dip is no longer 25px.
Let's teach you how to get this height on different devices. It's actually very simple:

Displaymetrics metrics = getresources (). Getdisplaymetrics ();
int status_bar_height = (int) Math.ceil (+ * metrics.density);

In fact, all we have to do is convert this 25dip height to px, because the height we need in the code is in PX.

How to get the height of StatusBar (Android platform)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.