Android development: two ways to get the height of the status bar

Android development: two ways to get the height of the status bar

In the development of Android applications, sometimes we need to obtain the height of the status bar for layout or other operations. This article will introduce two methods to obtain the height of the status bar, and attach the corresponding source code.

Method 1: Use system resources to obtain the height of the status bar

The Android system provides a resource file named "dimen", which defines various size values, including the height of the status bar. We can get the height of the status bar by accessing this resource file.

First, find the values ​​folder under the res folder of your project, and create a new one if there is no such folder. Then create a dimens.xml file under the values ​​folder, and add the following code to the file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="status_bar_height

Guess you like

Origin blog.csdn.net/update7/article/details/132374313