Android--> status bar height, navigation bar height, window height, decorview height, heightpixels

Source: Internet
Author: User

the height of the 1:decorview
The height of the Decorview represents the height of the entire decorative window, which includes: the height of the state rotten and the height of the navigation bar. (The status bar and navigation bar are often called decorative windows, while Actionbar is not part of the decoration window)

This height can represent the height of the entire glass screen.

height of the 2.Window rootview
Rootview access Method: GetWindow (). Findviewbyid (window.id_android_content);

This view corresponds to a height that can represent the current application's effective height.
In the absence of any modification, the height of the application is removed from the status bar and the navigation bar;

i.e. (height of the Decorview)-(height of the status bar)-(height of the navigation bar);

However, if you use:
Setsystemuivisibility (View.system_ui_flag_layout_fullscreen | View.system_ui_flag_hide_navigation);
This method, then the height of the rootview will be equal to the height of the Decorview;

the height of the 3:heightpixels
Heightpixels
This height means ... The height of the screen is effective;;;
What do you mean?
is: the height of the Decorview removes the height of the navigation bar.
This height no matter whether you have hidden the navigation bar, this value will not change;

So:
pan out: If you want to know if your phone has a navigation bar:
if (decorview height)-(heightpixels) > 0 Description Your phone has a navigation bar

pan out: If you want to know if your program has hidden navigation bar:
Scenario 1: Set the System_ui_flag_layout_fullscreen property:
if (rootview height)-(heightpixels) > 0 Description shows the navigation bar

Scenario 2: The System_ui_flag_layout_fullscreen property is not set:
if (rootview height + status bar height)-(heightpixels) > 0 Description Show navigation bar

Additional 1 Gets the height of the status bar
Under normal conditions: (heightpixels)-(height of rootview) = height of the status bar
But if you set the View.system_ui_flag_layout_fullscreen or View.system_ui_flag_hide_navigation attribute,,, this method is inaccurate.

Magnum, 100% Accurate method:
Getresources (). Getdimensionpixelsize (Getresources (). Getidentifier ("Status_bar_height", "Dimen", "Android"));

Add 2: Get the height of the navigation bar
Normal: (height of Decorview)-(heightpixels) = height of navigation bar
But if you set the View.system_ui_flag_hide_navigation attribute,,, this method is inaccurate.

Magnum, 100% Accurate method:
Getresources (). Getdimensionpixelsize (Getresources (). Getidentifier ("Navigation_bar_height", "Dimen", "Android"));

Android--> status bar height, navigation bar height, window height, decorview height, heightpixels

Related Article

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.