Size of android notification bar and title bar?
Maybe this is a helpful approach: Referring to the Icon Design Guidelines there are only three different heights for the status (notification) bar depending on the screen density:
- 24px for LDPI
- 32px for MDPI
- 48px for HDPI
So if you retrieve the screen density of the device using densityDpi
of DisplayMetrics you know which value to subtract
so it could look something like that:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int myHeight = 0;
switch (metrics.densityDpi) {
case DisplayMetrics.DENSITY_HIGH:
Log.i("display", "high");
myHeight = display.getHeight() - 48;
break;
case DisplayMetrics.DENSITY_MEDIUM:
Log.i("display", "medium/default");
myHeight = display.getHeight() - 32;
break;
case DisplayMetrics.DENSITY_LOW:
Log.i("display", "low");
myHeight = display.getHeight() - 24;
break;
default:
Log.i("display", "Unknown density");
Height of status bar in Android
this question was answered before...
Height of statusbar?
Update::
Current method:
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("*** Elenasys :: ", "StatusBar Height= " + statusBarHeight + " , TitleBar Height = " + titleBarHeight);
(old Method) 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;
}
Getting the size of the window WITHOUT title/notification bars
Use View.MeasureSpec.getSize method in onMeasure override.
@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
...
}
How to increase the size of the title bar in an Android application?
This is android title bar and you can not increase its size. It you need this feature in your application then you can create a custom title bar.
Remove the this default Title bar by using this code in your activity..
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
or this in your manifast inside your activity tag.
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
and then create a custom title bar in your XML file.
Height of statusbar?
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);
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;
}
Related Topics
Copy Database File to Sdcard in Android
How to Apply Plugin to Only One Flavor in Gradle
Difference Between Android: and App: Prefix in Android Xml
How to Load Class Androidcomponentsextension After Upgrading the Android Gradle Plugin 7.1
Gcm Push Notification with ASP.NET
How to Resize a Android Webview After Adding Data in It
Get Latitude and Longitude with Geocoder and Android Google Maps API V2
Android Multidex Support Library Using Eclipse
How to Check the Internet Connection Periodically in Whole Application
Android: Unicode/Charset Problems When Sending an Sms (Sendtextmessage)
Could Not Find Com.Android.Tools.Lint:Lint-Gradle Android Studio 3
Custom Fonts in Android Phonegap