This article describes the Android programming implementation to get the title bar, status bar height, screen size, and simulate the home key method. Share to everyone for your reference, specific as follows:
1. Get the title bar height:
/**
* Get the height of the title bar *
* @param activity
* @return
/public
int Gettitleheight (activity activity) {
Rect Rect = new Rect ();
window window = Activity.getwindow ();
Window.getdecorview (). Getwindowvisibledisplayframe (rect);
int statusbarheight = rect.top;
int contentviewtop = Window.findviewbyid (window.id_android_content). GetTop ();
int titlebarheight = contentviewtop-statusbarheight;
return titlebarheight;
}
2. Get the height of the status bar:
/**
* *
get status bar height
* *
@param activity
* @return
/public int getstateheight ( Activity activity) {
Rect Rect = new Rect ();
Activity.getwindow (). Getdecorview (). Getwindowvisibledisplayframe (rect);
return rect.top;
}
3. Screen Size:
/** *
Get screen width high
*
* @param activity
* @return int[0] wide, int[1] high * * Public
int[] GETSCREENWIDTHANDSIZEINPX (activity activity) {
displaymetrics displaymetrics = new Displaymetrics ();
Activity.getwindowmanager (). Getdefaultdisplay (). Getmetrics (displaymetrics);
int[] size = new INT[2];
Size[0] = displaymetrics.widthpixels;
SIZE[1] = displaymetrics.heightpixels;
return size;
}
4. Simulate the Home key:
/**
* Simulate Home key
* *
@param context
/public
void Gotodestop {
Intent Intent = new Intent (intent.action_main);
Intent.setflags (intent.flag_activity_new_task);
Intent.addcategory (intent.category_home);
Context.startactivity (intent);
}
I hope this article will help you with the Android program.