在Android的状态栏高度 [英] Height of status bar in Android

查看:152
本文介绍了在Android的状态栏高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在Android的状态栏的高度?是不是总是一样的?

What's the height of the status bar in Android? Is it always the same?

从我的测试看来,这是25dp,但我不知道是否有相同的高度上的所有平台。

From my measurements it seems that it's 25dp, but I'm not sure if it has the same height on all platforms.

(我想知道这个正确地实现从一个没有状态栏,以一个没有活性的渐变过渡)

(I want to know this to properly implement a fade transition from an activity that doesn't have status bar to one that does)

推荐答案

这个问题被回答过... 状态栏的高度?

this question was answered before... Height of statusbar?

更新 ::好的,状态栏的高度取决于屏幕的大小,例如在设备 具有240×320的屏幕尺寸在状态栏高度为20像素,与320 X 480的屏幕尺寸在状态栏的高度是25像素的装置,用于480 x 800的设备状态栏的高度必须是38px

Update:: ok, the height of the status bar depends on the screen size, for example in a device with 240 X 320 screen size the status bar height is 20px, for a device with 320 X 480 screen size the status bar height is 25px, for a device with 480 x 800 the status bar height must be 38px

所以我建议使用这个脚本来获取状态栏高度

so i recommend to use this script to get the status bar height

Rect rectangle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight= rectangle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;

   Log.i("*** Jorgesys :: ", "StatusBar Height= " + statusBarHeight + " , TitleBar Height = " + titleBarHeight); 

让您的活动的的onCreate()法的状态栏的高度,用这个方法:

to get the Height of the status bar on the onCreate() method of your Activity, use this method:

public int getStatusBarHeight() { 
      int result = 0;
      int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
      if (resourceId > 0) {
          result = getResources().getDimensionPixelSize(resourceId);
      } 
      return result;
} 

这篇关于在Android的状态栏高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆