Home » » Get the height of status bar

Get the height of status bar

Posted by Android Flash Firmware on Monday, February 13, 2017

Example to get the height of status bar, in size of pixel.



package com.blogspot.android_er.androidgetstatusbarheight;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getStatusBarHeight();
}

private int getStatusBarHeight() {
int height;

Resources myResources = getResources();
int idStatusBarHeight = myResources.getIdentifier(
"status_bar_height", "dimen", "android");
if (idStatusBarHeight > 0) {
height = getResources().getDimensionPixelSize(idStatusBarHeight);
Toast.makeText(this,
"Status Bar Height = " + height,
Toast.LENGTH_LONG).show();
}else{
height = 0;
Toast.makeText(this,
"Resources NOT found",
Toast.LENGTH_LONG).show();
}

return height;
}

}



0 comments:

Post a Comment

Popular Posts

Blog Archive

.comment-content a {display: none;}