简体   繁体   English

如何在Android中获取通知栏的高度和宽度?

[英]How to get the height and width of the notification bar in android?

So i know how to get the screen size of an android device. 所以我知道如何获取Android设备的屏幕尺寸。

But how do i get the the size of the notification bar which comes in the top? 但是,如何获取顶部通知栏的大小?

   DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    height = displaymetrics.heightPixels;
    width = displaymetrics.widthPixels;

This question was already answered : Height of status bar in Android 该问题已经得到回答: Android中状态栏的高度

But you can do this like this : 但是您可以这样:

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM