Android programming enables you to get the title bar, the height of the status bar, the screen size, and the method to simulate the home key _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.